Search⌘ K
AI Features

Delete Documents

Understand how to delete documents in MongoDB using the deleteOne and deleteMany commands. Learn to remove single or multiple documents, interpret command responses, and recognize collection types where deletion commands do not apply.

Delete a single document

Syntax for the deleteOne command:

db.<collection-name>.deleteOne(
    <filter query>,
    <options>
);

The filter query and options in the deleteOne command behave the same as they do in the updateOne command. The only difference is that deleteOne deletes only one document.

Below is an example of a query to delete a document by _id.

Markdown
db.tasks.deleteOne({
_id: ObjectId("60f7d855b307d94301b9cb90")
});

This query ...