---
title: "How can you perform CRUD operations in MongoDB and what are some common techniques for doing so?"  
description: "How can you perform CRUD operations in MongoDB and what are some common techniques for doing so?"  
author: "Revati S Misra"  
published: 2023-05-16  
updated: 2023-05-18  
canonical: https://www.mindstick.com/forum/158368/how-can-you-perform-crud-operations-in-mongodb-and-what-are-some-common-techniques-for-doing-so  
category: "mongodb"  
tags: ["database", "mongodb", "mongodb query"]  
reading_time: 3 minutes  

---

# How can you perform CRUD operations in MongoDB and what are some common techniques for doing so?

What are some [common](https://www.mindstick.com/articles/23170/10-most-common-accounting-mistakes-of-small-business) use cases for [MongoDB](https://www.mindstick.com/articles/337565/understanding-document-stores-a-look-at-mongodb-vs-couchdb) and how can it be used in a real-[world](https://yourviews.mindstick.com/view/87468/defining-humanity-as-given-in-sanatan-dharma-best-in-world) [application](https://www.mindstick.com/articles/12824/calculator-application-in-android)?

## Replies

### Reply by Aryan Kumar

\
CRUD stands for Create, Read, Update, and Delete. These are the four basic operations that can be performed on data in a database.

In MongoDB, CRUD operations can be performed using the following methods:

- **Create:** To create a document in a collection, use the insert() method. The insert() method takes a list of documents as its argument. The following is an example of how to create a document in a collection:

Code snippet

```plaintext
db.collection.insert([
  {
    "name": "John Doe",
    "age": 30
  }
])
```

- **Read:** To read documents from a collection, use the find() method. The find() method takes a query object as its argument. The query object specifies the criteria that documents must match in order to be returned. The following is an example of how to read documents from a collection:

Code snippet

```plaintext
db.collection.find({
  "name": "John Doe"
})
```

- **Update:** To update a document in a collection, use the update() method. The update() method takes a query object and an update object as its arguments. The query object specifies the criteria that documents must match in order to be updated. The update object specifies the changes that are to be made to the documents. The following is an example of how to update a document in a collection:

Code snippet

```plaintext
db.collection.update({
  "name": "John Doe"
}, {
  "$set": {
    "age": 31
  }
})
```

- **Delete:** To delete a document from a collection, use the deleteOne() or deleteMany() method. The deleteOne() method deletes a single document that matches the query object. The deleteMany() method deletes all documents that match the query object. The following is an example of how to delete a document from a collection:

Code snippet

```plaintext
db.collection.deleteOne({
  "name": "John Doe"
})
```

Here are some common techniques for performing CRUD operations in MongoDB:

- **Using the MongoDB shell:** The MongoDB shell is a powerful tool that can be used to perform CRUD operations on data in a MongoDB database. The MongoDB shell provides a number of commands that can be used to perform CRUD operations.
- **Using the MongoDB driver:** The MongoDB driver is a library that can be used to interact with a MongoDB database from a variety of programming languages. The MongoDB driver provides a number of methods that can be used to perform CRUD operations.
- **Using the MongoDB API:** The MongoDB API is a set of RESTful APIs that can be used to interact with a MongoDB database from any web application. The MongoDB API provides a number of endpoints that can be used to perform CRUD operations.

CRUD operations are the basic building blocks of data manipulation in MongoDB. By understanding how to perform CRUD operations, you can effectively manage data in a MongoDB database.


---

Original Source: https://www.mindstick.com/forum/158368/how-can-you-perform-crud-operations-in-mongodb-and-what-are-some-common-techniques-for-doing-so

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
