I am making a radio automation app that stores it's playlists in a mongoDB. Each document in the playlists
collection looks something like this:
{
'name': 'My cool playlist',
'items': [
{'fileID': 'Cr4tT47K4EfJGQzfg'},
{'fileID': 'Cr4tT49K4EfJGxffg'},
{'fileID': 'Cr4tT49KH7EfJGQzfg'},
{'fileID': '45otT49K4EfJGQzfg'},
{'fileID': 'Dr4tT49K4EfJGQzfg'},
]
}
I'm trying to use this query to insert an array of elements at a certain position:
$push: {'items': { $each: insertArray, $position: insertPos}}
(insertArray
is the array of elements to insert. insertPos
is the variable containing the position at which I want the array to be inserted.)
MongoDB gives me this error: MongoError: $each term takes only $slice (and optionally $sort) as complements
I'm using mongoDB version 2.4.9 from Meteor 0.9.2.2. In other words, I'm actually querying minimongo which emulates mongoDB.
Your query won't work with MongoDB 2.4.9 because the $position
operator was added in 2.6.