Docs Menu

collection.deleteOne()icons/link.png

On this page

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

Remove a single document from the collection based on a query.

To call the collection.deleteOne() action from a Function, get a collection handle with database.collection() then call the handle's deleteOne() method.

const query = { "name": "lego" };
itemsCollection.deleteOne(query)
.then(result => console.log(`Deleted ${result.deletedCount} item.`))
.catch(err => console.error(`Delete failed with error: ${err}`))

The collection.deleteOne() action has the following form:

deleteOne(query)
Parameter
Description

Query

query: <document>

Optional. A standard MongoDB query document that specifies which document to delete. You can use most query selectors except for evaluation, geospatial, or bitwise selectors.

If multiple documents match the query, only the first document in sort order or natural order will be deleted.

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.deleteOne() 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
MongoDB logo
© 2021 MongoDB, Inc.

About

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