There is a query parameter and an update tag in findAndMondify.
But how to limit the number of searches?
That is, combine the following two statements into one
db.xxx.find({name:"xxx" ,age:3}).limit(10)
db.xxx.update({name:"xxx"},{$set:{age:5}},false,true)
曾经蜡笔没有小新2017-05-17 10:05:22
The
findAndModify
method is used to put search and modification in an atomic operation, which can only operate on one piece of data at a time.
You can refer to the documentation for specific usage:
sort document Optional. Determines which document the operation modifies if the query selects multiple documents. findAndModify() modifies the first document in the sort order specified by this argument.