Read Operations

The Read operations are used to retrieve documents from the collection, or in other words, read operations are used to query a collection for a document.

You can perform read operation using the following method provided by the MongoDB:

Method Description
db.collection.find() It is used to retrieve documents from the collection.
Note: pretty() method is used to decorate the result such that it is easy to read.

Read Operations Example

Let’s look at some examples of Read operation from CRUD in MongoDB.

Example: In this example, we are retrieving the details of students from the student collection using db.collection.find() 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 operationsCREATE, READ, UPDATE, and DELETE that form the CRUD operations in MongoDB.

Similar Reads

Perform CRUD Operations in MongoDB

Now that we know the components of the CRUD operation, let’s learn about each individual operation in MongoDB. We will know what each operation does, and the methods to perform these operations in MongoDB....

1. Create Operations

The create or insert operations are used to insert or add new documents in the collection. If a collection does not exist, then it will create a new collection in the database....

2. Read Operations

The Read operations are used to retrieve documents from the collection, or in other words, read operations are used to query a collection for a document....

3. Update Operations

The update operations are used to update or modify the existing document in the collection. You can perform update operations using the following methods provided by the MongoDB:...

4. 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:...

Conclusion

CRUD operations are the fundamentals of MongoDB. MongoDB CRUD operations let user interact with the MongoDB server. They provide operations to create, read, update and delete documents from the collection in database....

Contact Us