Docs Menu

collection.deleteMany()

On this page

  • Definition
  • Usage
  • Example
  • Parameters
  • Return Value
collection.deleteMany()

Remove one or more documents from the collection based on a query filter.

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}`))

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.

Client Session

session: <ClientSession>
Optional. A client session that specifies the transaction context in which the operation occurs. To learn more, see Transactions.

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
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.