Atomically Modifying Documents in a Collection
The Collection
object provides the findAndModify()
function, which performs an atomic write on a single document in a collection. This is extremely useful if you need to ensure that no other processes can write to your document at the same time. The following is the syntax for the findAndModify()
method:
findAndModify(query, sort, update, [options], callback)
The query
parameter is a document that is used to identify which document you want to modify. The request matches the properties and values in the query
parameter with the fields and values of the object, and only those that match the query are modified.
The sort
parameter is an array of [field, sort_order]
pairs ...
Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.