I wanted to know if its possible to use $slice without the $each in mongoose. I'm trying to push to an array of songs but when it reaches a point of 10 songs, for the array to slice the old songs out of the array. Is this even possible and if not is there a trick to performing this action?
Code I have so far but it isn't slicing anything:
Playlist.findByIdAndUpdate(playlist._id,
{ $push:{ "songs" : song, $slice: -2 }},
{ safe: true, upsert: true },
function( err, model ) {
cb(err, model);
}
);
Aucun commentaire:
Enregistrer un commentaire