1

I'm writing a music organization app with the latest version of Meteor (A new web framework.). I think that the best way to store playlists is to put each playlist in a document and put the items of the playlist in array inside the document. It looks something like this:

{
  "name": "a very cool playlist"
  "items: [
    {"audioFileID": 144}
    {"audioFileID": 443}
    {"audioFileID": 035}
    {"audioFileID": 442}
  ]
}

My problem is that that minimongo (Meteor's pure javascript MongoDB implementation) only supports MongoDB 2.4. That means I can't use the $position operator to insert a playlist element in the middle of the playlist. What's the best way to get around this? I can't believe that nobody had a way to insert items into the middle of an array before MongoDB 2.6. Or maybe there's a way to easily patch minimongo.

BonsaiOak
  • 27,741
  • 7
  • 30
  • 54
  • 1
    You could probably do something with using the [`$sort`](http://docs.mongodb.org/manual/reference/operator/update/sort/#sort) modifier on a `$push`, but you'd have to add a field to your elements to sort on. – JohnnyHK Oct 08 '14 at 12:54
  • @JohnnyHK I guess that means that I'm down to the options explained to me in [my other question about ordering documents within collections](http://stackoverflow.com/questions/26220879) – BonsaiOak Oct 08 '14 at 15:49
  • 1
    Unless it is a client-only collection, you could do it with meteor method on the server (though this will cost the latency compensation) – Rune Jeppesen Oct 10 '14 at 11:56
  • @RuneJeppesen Are you saying that I could use MongoDB 2.6 on the server, and thus have direct access to the extra operators? – BonsaiOak Oct 10 '14 at 16:36
  • BonsaiOak yes. Though I am not sure what version the server uses :-\ – Rune Jeppesen Oct 10 '14 at 20:54
  • @RuneJeppesen The latest version of Meteor uses MongodB v2.4.9. However, I understand that it's possible to point Meteor at any MongoDB server, so I don't see why I couldn't point it to a server running v2.6.* Does that sound reasonable? – BonsaiOak Oct 10 '14 at 22:44
  • Worth a shot :-) I have not tried it – Rune Jeppesen Oct 11 '14 at 09:35

0 Answers0