Alexey Zakharov
Alexey Zakharov

Reputation: 25120

How can i perform mongodb findAndModify only for first matched document?

I need to find and modify first matched element using mongodb. Is it possible? I failed to find how to do it from official doc: http://www.mongodb.org/display/DOCS/findAndModify+Command

There is not findAndModifyOne method.

Upvotes: 3

Views: 3958

Answers (1)

dcrosta
dcrosta

Reputation: 26278

According to the docs "This command can be used to atomically modify a document (at most one) and return it." (emphasis mine)

Edit: If you use the sort argument to findAndModify, then it will operate on the first result found according to the sort criteria.

Upvotes: 5

Related Questions