Updating Documents in a Collection
Once objects have been inserted into a collection, you may need to update them from time to time as the data changes. The MongoDB Node.js driver provides several great methods for updating documents. The most commonly used is the update()
method, which is versatile and yet fairly easy to implement. The following is the syntax for the update()
method:
update(query, update, [options], [callback])
The query
parameter is a document that is used to identify which document(s) you want to change. 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 updated. The update
parameter is an object ...
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.