Updating a Single Document
The Document
object provides the update()
method, which allows you to update a single document by using the update
operators described in Table 14.2. The syntax for the update()
method on Document
objects is shown below:
update(update, [options], [callback])
The update
parameter defines the update operation to perform on the document. The options
parameter specifies the write preferences, and the callback
parameter accepts an error as the first argument and the number of documents updated as the second.
Listing 16.6 shows an example of using the update()
method to update the word gratifaction
to gratifactions
by setting word
, size
, and last
fields, using a $set
operator as well as pushing ...
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.