collection.deleteMany()¶
Definition¶
collection.deleteMany()
¶
Remove one or more documents from the collection based on a query filter.
Usage¶
Example¶
To call the collection.deleteMany()
action from a function, get a collection handle with
database.collection()
then call the handle's deleteMany()
method.
const query = { "reviews": { "$size": 0 } }; itemsCollection.deleteMany(query) .then(result => console.log(`Deleted ${result.deletedCount} item(s).`)) .catch(err => console.error(`Delete failed with error: ${err}`))
Parameters¶
The collection.deleteMany()
action has the following form:
deleteMany(query)
Parameter | Description |
---|---|
Query Filter query: <document> | Optional. A standard MongoDB query document that specifies which
documents to delete. You can use most query selectors except for
evaluation,
geospatial,
or bitwise
selectors. |
Return Value¶
The collection.deleteMany()
action returns a Promise that
resolves to a document that describes the delete operation.
Promise<result: document>
Value | Description |
---|---|
Matched Count result.deletedCount: <integer> | The number of documents in the collection that were deleted by
the delete operation. |
Give Feedback