Docs Menu

Docs HomeDevelop ApplicationsMongoDB DriversC#/.NET

Delete a Document

On this page

  • Example
  • Delete a Document by Using Builders
  • Expected Result
  • Additional Information
  • API Documentation

You can delete a document from a collection by using the synchronous DeleteOne() method, or the asynchronous DeleteOneAsync() method.

Note

The DeleteOne() method deletes only the first document that matches the filter. To delete more than one document, use the DeleteMany() method.

To learn more about using DeleteMany(), see Delete Many Documents.

The following example uses Builders to delete a document in the restaurants collection with the name "Ready Penny Inn".

Select the Asynchronous or Synchronous tab to see the corresponding code.

Running either of the preceding full examples prints the following results:

Deleting a document with builders...
Deleted documents: 1

To learn more about deleting documents, see the Delete Documents guide.

To learn more about using builders, see Operations with Builders.

  • DeleteOne()

  • DeleteOneAsync()

← Replace a Document