Removing Multiple Documents

The Model object’s remove() method allows you to delete multiple documents in a collection by using a single call to the database. The syntax for the remove() method on Model objects is shown below:

update(query, [options], [callback])

The query parameter defines the query used to identify which objects to delete. The options parameter specifies the write preferences, and the callback parameter accepts an error as the first argument and the number of documents deleted as the second.

A nice thing about deleting at the model level is that you delete multiple documents in the same operation, saving the overhead of multiple requests. Also, you can use the Query object to define which objects ...

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.