MongoDB is the Document-Based distributed database system that provides rich functionality to read and write the data and these operations are achieved through MongoDB CRUD. The MongoDB CRUD stands for CREATE, READ, UPDATE and DELETE which are used to perform the operation such as create, update, read and delete on MongoDB Documents. Using these operations we can easily interact with the database and perform various tasks.

The following figure represents the MongoDB CRUD operation.

Mongodb CRUD operation


MongoDB CRUD Concepts

The MongoDB CRUD concept has two operations, the first one is Read Operation and the second one is Write operation. In Read Operation we have READ operation and in the Write operation we have CREATE, UPDATE AND DELETE operation as mentioned in the below figure.

Mongodb CRUD concepts

Let us understand the MongoDB CRUD operations in the below section.


Create Operations in MongoDB

MongoDB Create Operations are used to create a new Document in a Collection. In case the Collection is not present then it creates the Collection as well.

The below two methods are used for MongoDB Create Operations.

  • db.collection_name.insertOne()
  • db.collection_name.insertMany()

In the following example, we can see the Collection "users_detail" is created with the below data.

Mongodb create operations


Read Operations in MongoDB

MongoDB Read Operations are used to read the Documents from the Collection.

MongoDB provides the following method to perform the Read Operations.

  • db.collection_name.find()

The following is an example of Read Operations in MongoDB.

Mongodb read operations


Update Operations in MongoDB

MongoDB Update Operations are used to modify existing Documents in the Collection.

The following methods are used to perform the Update Operations in MongoDB.

  • db.collection_name.updateOne()
  • db.collection_name.updateMany()
  • db.collection_name.replaceOne()

The following is an example of Update Operations in MongoDB.

Mongodb update operations


Delete Operations in MongoDB

MongoDB Delete Operations are used to delete the Documents from the Collection.

The following methods are used to perform the Delete Operations in MongoDB.

  • db.collection.deleteOne()
  • db.collection.deleteMany()

The following is an example of Delete Operations in MongoDB.

Mongodb delete operations