Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return popped element in mongodb

I would like to pop one item from the array, and get that element.

Is it possible in mongodb?

I didn't find such information at

http://docs.mongodb.org/manual/reference/operator/pop/

like image 735
meso_2600 Avatar asked Dec 13 '12 00:12

meso_2600


1 Answers

This is not possible. MongoDB does not return any part of the document you previously had using a normal update, that being said it can return the full document, not just that popped element on findAndModify ( http://docs.mongodb.org/manual/reference/command/findAndModify/ ), you could then filter that element out, either the first or the last.

NB: I should warn that findAndModify is basically like picking out every document in the query and operating on it, that's how it is able to return it so you might see some performance loss on queries that span a large nummber.

like image 81
Sammaye Avatar answered Oct 29 '22 18:10

Sammaye