I am able to $push an object onto a Mongo array as follows:
db.foo.update({},{$push:{bar:3}})
But I can’t find a syntax that will allow me to $pop the last item from the list.
I’ve tried things like:
db.foo.find({$pop:{bar:1}})
which does nothing. I’ve also tried
db.foo.find({id:23},{$pop:{bar:1}})
which outputs:
error: { "$err" : "Unsupported projection option: bar", "code" : 13097 }
Any ideas?
$popexists and works almost like you’ve got it there, but you need to find some elements first!See the docs.