Saving Documents in a Collection

The save() method on Collection objects is kind of interesting. You can use it to insert or update a document in a database. Although it is not as efficient as insert() or update(), the save() method is easier to implement in some circumstances. For example, when you are making ad hoc changes to objects already retrieved from a MongoDB database, you can use save() without having to implement the query and update objects of the update() method.

The following is the syntax of the save() method:

save(doc, [options], [callback])

The doc parameter is the document object you want to save to the collection. The options parameter specifies the database change options described in Table 14.1 ...

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.