CRUD operations form the backbone of any database-driven application. In MongoDB, CRUD stands for Create, Read, Update, and Delete—the four fundamental actions you perform on data.

If you’re new to MongoDB, mastering these operations will give you the confidence to build real-world applications. This guide explains MongoDB CRUD operations in a clear, beginner-friendly way, with practical examples.


What Are CRUD Operations?

OperationPurpose
CreateInsert new data
ReadRetrieve existing data
UpdateModify existing data
DeleteRemove data

In MongoDB, CRUD operations are performed on collections, and each record is stored as a document.


Getting Started: Example Collection

Let’s assume we have a users collection in a database called appDB.

Sample document:

{ "name": "Rahul", "email": "rahul@example.com", "age": 28, "isActive": true }

1. Create: Inserting Documents in MongoDB

Insert a Single Document

db.users.insertOne({ name: "Rahul", email: "rahul@example.com", age: 28, isActive: true });

MongoDB automatically adds a unique _id field.


Insert Multiple Documents

db.users.insertMany([ { name: "Anita", age: 25, isActive: true }, { name: "Rohit", age: 30, isActive: false } ]);

2. Read: Querying Documents in MongoDB

Find All Documents

db.users.find();

Find with Conditions

db.users.find({ isActive: true });

Find One Document

db.users.findOne({ name: "Rahul" });

Projection (Select Specific Fields)

db.users.find( { isActive: true }, { name: 1, email: 1, _id: 0 } );

3. Update: Modifying Documents in MongoDB

Update One Document

db.users.updateOne( { name: "Rahul" }, { $set: { age: 29 } } );

Update Multiple Documents

db.users.updateMany( { isActive: false }, { $set: { isActive: true } } );

Replace a Document

db.users.replaceOne( { name: "Anita" }, { name: "Anita", age: 26, isActive: true } );

⚠️ replaceOne removes fields not included in the new document.


4. Delete: Removing Documents in MongoDB

Delete One Document

db.users.deleteOne({ name: "Rohit" });

Delete Multiple Documents

db.users.deleteMany({ isActive: false });

Delete All Documents (Use with Caution)

db.users.deleteMany({});

5. Understanding Filters and Operators

MongoDB supports powerful query operators.

Comparison Operators

db.users.find({ age: { $gt: 25 } });
  • $gt → greater than

  • $lt → less than

  • $gte, $lte, $ne


Logical Operators

db.users.find({ $and: [ { isActive: true }, { age: { $gte: 25 } } ] });

6. Common CRUD Mistakes Beginners Make

  • Forgetting filters in update or delete operations

  • Using updateMany accidentally

  • Not using $set (overwriting documents)

  • Deleting data without backup

👉 Always double-check your query before executing it.


7. CRUD Operations Using MongoDB Compass

MongoDB Compass allows you to:

  • Insert documents visually

  • Edit fields inline

  • Apply filters without code

  • Delete documents safely

This is great for beginners and debugging.


8. Best Practices for CRUD Operations

  • Use indexes for frequently queried fields

  • Validate data before inserting

  • Avoid large documents

  • Test update and delete queries carefully

  • Backup important data regularly


Final Thoughts

CRUD operations are the foundation of MongoDB. Once you master Create, Read, Update, and Delete, you’re ready to move on to advanced topics like indexing, aggregation, and schema design.

MongoDB’s simple and flexible CRUD syntax makes it beginner-friendly and powerful at the same time.