Model helper methods
There are three static methods for updating data in a single go:
update()
: This method updates matching documents in the database without returning themfindOneAndUpdate()
: This method has the same approach asfindOne
that we looked at earlier, but writes the updates to the database before returning the found instance to the callbackfindByIdAndUpdate()
: This method is the same asfindOneAndUpdate
, but expects a unique ID instead of query object
Building the commands
Each of these methods can take the following four arguments:
conditions
: These are the query conditions (or_id
forfindByIdAndUpdate
) used to find documents to updateupdate
: This is an object containing the fields and values to setoptions
: This is an object specifying options for this operation (see more details about this in just a moment)callback
: This is the function to run after a successful operation
The options differ depending on the call made. The update() method has one set of options you can set...