Navigation

collection.deleteOne()

On this page

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

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

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 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.

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

On this page

  • Definition
  • Usage
  • Example
  • Parameters
  • Return Value