Delete Operations
The delete operation are used to delete or remove the documents from a collection. You can perform delete operations using the following methods provided by the MongoDB:
Method | Description |
---|---|
db.collection.deleteOne() | It is used to delete a single document from the collection that satisfy the given criteria. |
db.collection.deleteMany() | It is used to delete multiple documents from the collection that satisfy the given criteria. |
Delete Operations Examples
Let’s look at some examples of delete operation from CRUD in MongoDB.
Example 1: In this example, we are deleting a document from the student collection using db.collection.deleteOne() method. Example 2: In this example, we are deleting all the documents from the student collection using db.collection.deleteMany() method.
MongoDB CRUD Operations
CRUD Operations (Create, Read, Update, and Delete) are the basic set of operations that allow users to interact with the MongoDB server.
As we know, to use MongoDB we need to interact with the MongoDB server to perform certain operations like entering new data into the application, updating data into the application, deleting data from the application, and reading the application data.
In this article, we will learn all 4 major operations– CREATE, READ, UPDATE, and DELETE that form the CRUD operations in MongoDB.
Contact Us