How to return popped element in mongodb

I would like to put one element from an array and get this element.

Is this possible in mongodb?

I did not find such information in

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

+4
source share
2 answers

It's impossible. MongoDB does not return any part of the document that you previously used with regular updating, nor can it return the full document, and not just this pop-up element to findAndModify ( http://docs.mongodb.org/manual/reference/command/ findAndModify / ), you can filter this element both the first and the last.

NB: I have to warn that findAndModify is basically like collecting each document in a query and working with it, how it can return it so you can see some performance loss on queries that span a large numeric number.

+3
source

MongoDB operations return full documents .

Parameters can be:

  • Use the findAndModify command and get the pop-up value of the side of the array program by processing the returned document. (1 request)
  • use find to get the document, get the value you want to set on the program side, and send update . (2 requests)
+2
source

All Articles