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.
We'll cover the following...
We'll cover the following...
Delete a single document
Syntax for the deleteOne command:
db.<collection-name>.deleteOne(
<filter query>,
<options>
);
The
filter queryandoptionsin thedeleteOnecommand behave the same as they do in theupdateOnecommand. The only difference is thatdeleteOnedeletes only one document.
Below is an example of a query to delete a document by _id.
This query ...