Removing a Single Document from a Collection
You can delete a single document from a database by using the findAndRemove()
method. This is very similar to the findAndModify()
method in syntax and application. The following is the syntax for the findAndRemove()
method:
findAndRemove(query, sort, [options], callback)
The query
parameter is a document that is used to identify the document to remove. 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
parameter are modified.
The sort
parameter is an array of [field, sort_order]
pairs that specify which fields to sort on when finding the item to remove. sort_order
is set to ...
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.