LearnBoost/mongoose — Issue #574: $pop: {field:-1} isn't working
Author: alejandromg
Created: 2011-10-24 00:21:25+00:00
State: open

If you want to delete the first element of an array the `$pop : {field:-1}` should work. But mongoose always delete the last element of the array.

I'm using this code:

if (data.history && data.history.length >= 10) {
for (var i = 1; i <= (data.history.length - 10); i++) {
User.update({username: req.params.user}, {$pop: {history: -1}},{upsert:true}, function(err) {
if (err) throw err;
res.end('ok');
});
}
}