Navigation

collection.deleteOne()

Definition

collection.deleteOne()

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

Usage

Example

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

Parameters

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

deleteOne(query)
Parameter Description

Query Filter

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.

Return Value

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.