I want to delete the last 2 elements from an array object.
{
"_id" : ObjectId("597973c8c9fadd14e8ea51bb"),
"values" : [1,2,3,4,5,6]
}
I have tried $pop but it delete only one element each time. Is there any convenient way?
I want to delete the last 2 elements from an array object.
{
"_id" : ObjectId("597973c8c9fadd14e8ea51bb"),
"values" : [1,2,3,4,5,6]
}
I have tried $pop but it delete only one element each time. Is there any convenient way?
There's no way to do this as far as I know. The closest you can do would probably to get the list in your application ($slice to make it smaller if you prefer), put the last n items in an array and do a $pull. It'll pull all similar elements though.
If that's not an option, repeating $pop seems to be the only way.