MongoDB CRUD Operations Complete Beginner Guide
Learn Create, Read, Update, and Delete operations in MongoDB with easy examples, practice questions, and MCQs.
MongoDB CRUD Operations are the basic operations used to manage data inside a MongoDB database. CRUD is one of the most important topics for beginners who are learning MongoDB, backend development, or MERN Stack development.
What is CRUD in MongoDB?
CRUD stands for:
| Letter | Meaning |
|---|---|
| C | Create |
| R | Read |
| U | Update |
| D | Delete |
CRUD operations are used to insert, read, update, and delete data from a database. Almost every website and application uses CRUD operations.
Registration form uses Create operation.
Profile page uses Read operation.
Edit profile uses Update operation.
Delete account uses Delete operation.
Create Operation in MongoDB
Create operation is used to insert new documents into a MongoDB collection.
- insertOne()
- insertMany()
Insert One Document
db.students.insertOne({
name: "Harsh",
age: 21,
course: "BCA",
marks: 85
})
Insert Multiple Documents
db.students.insertMany([
{
name: "Rahul",
age: 20,
course: "BCA",
marks: 75
},
{
name: "Aman",
age: 22,
course: "BTech",
marks: 90
}
])
Read Operation in MongoDB
Read operation is used to fetch or display data from a MongoDB collection.
Show All Documents
db.students.find()
Find One Document
db.students.findOne()
Find Data Using Condition
db.students.find({
course: "BCA"
})
Update Operation in MongoDB
Update operation is used to modify existing documents in a collection.
Update One Document
db.students.updateOne(
{ name: "Harsh" },
{
$set: {
marks: 95
}
}
)
Update Multiple Documents
db.students.updateMany(
{ course: "BCA" },
{
$set: {
status: "Pass"
}
}
)
Delete Operation in MongoDB
Delete operation is used to remove documents from a collection.
Delete One Document
db.students.deleteOne({
name: "Rahul"
})
Delete Multiple Documents
db.students.deleteMany({
course: "BCA"
})
MongoDB Update Operations and Important Update Operators
In MongoDB, update operations are used when we want to change existing data inside a collection. The two most common update methods are updateOne() and updateMany().
| Method | Use |
|---|---|
| updateOne() | Updates only the first matching document. |
| updateMany() | Updates all documents that match the condition. |
Sample Data for Update Queries
db.students.insertMany([
{
name: "Harsh",
age: 21,
course: "BCA",
marks: 85,
skills: ["HTML", "CSS"]
},
{
name: "Rahul",
age: 20,
course: "BCA",
marks: 70,
skills: ["JavaScript"]
},
{
name: "Aman",
age: 22,
course: "MCA",
marks: 90,
skills: ["MongoDB", "Node.js"]
}
])
1. $set Operator
The $set operator is used to update an existing field value or add a new field if it does not exist.
db.students.updateOne(
{ name: "Harsh" },
{
$set: {
marks: 95,
city: "Delhi"
}
}
)
2. $unset Operator
The $unset operator is used to remove a field from a document.
db.students.updateOne(
{ name: "Harsh" },
{
$unset: {
city: ""
}
}
)
3. $inc Operator
The $inc operator is used to increase or decrease a numeric field value.
db.students.updateOne(
{ name: "Rahul" },
{
$inc: {
marks: 5
}
}
)
db.students.updateOne(
{ name: "Rahul" },
{
$inc: {
marks: -10
}
}
)
4. $push Operator
The $push operator is used to add a new value inside an array field.
db.students.updateOne(
{ name: "Harsh" },
{
$push: {
skills: "JavaScript"
}
}
)
5. $each Operator with $push
The $each operator is used with $push to add multiple values inside an array at the same time.
db.students.updateOne(
{ name: "Harsh" },
{
$push: {
skills: {
$each: ["PHP", "MySQL", "React"]
}
}
}
)
6. $pop Operator
The $pop operator is used to remove first or last value from an array.
db.students.updateOne(
{ name: "Harsh" },
{
$pop: {
skills: 1
}
}
)
db.students.updateOne(
{ name: "Harsh" },
{
$pop: {
skills: -1
}
}
)
7. $pull Operator
The $pull operator is used to remove a specific value from an array.
db.students.updateOne(
{ name: "Harsh" },
{
$pull: {
skills: "CSS"
}
}
)
8. $addToSet Operator
The $addToSet operator adds a value to an array only if that value is not already present. It helps to avoid duplicate values.
db.students.updateOne(
{ name: "Harsh" },
{
$addToSet: {
skills: "MongoDB"
}
}
)
9. $rename Operator
The $rename operator is used to rename a field name.
db.students.updateMany(
{},
{
$rename: {
marks: "score"
}
}
)
10. Update Many Documents
We can use updateMany() to update all matching documents.
db.students.updateMany(
{ course: "BCA" },
{
$set: {
status: "Pass"
}
}
)
Quick Revision Table of MongoDB Update Operators
| Operator | Use | Example Meaning |
|---|---|---|
| $set | Update or add field | marks: 95 |
| $unset | Remove field | Remove city field |
| $inc | Increase or decrease number | marks +5 or -10 |
| $push | Add value in array | Add JavaScript in skills |
| $each | Add multiple array values | Add PHP, MySQL, React |
| $pop | Remove first or last array value | 1 = last, -1 = first |
| $pull | Remove specific array value | Remove CSS |
| $addToSet | Add unique value in array | Avoid duplicate skills |
| $rename | Rename field | marks to score |
MongoDB CRUD Practice Questions
- Insert one student document.
- Insert multiple employee documents.
- Find all records from a collection.
- Find students whose marks are greater than 80.
- Use $set to update marks of one student.
- Use $unset to remove city field from one document.
- Use $inc to increase marks by 10.
- Use $inc to decrease age by 1.
- Use $push to add one skill in skills array.
- Use $each with $push to add multiple skills.
- Use $pop to remove last skill from skills array.
- Use $pull to remove a specific skill from skills array.
- Use $addToSet to add a skill without duplicate entry.
- Use updateMany() to add status field to all BCA students.
- Delete all records with marks below 40.
MongoDB CRUD MCQ Questions
Final Conclusion
MongoDB CRUD operations are the foundation of MongoDB. Every beginner should understand how to create, read, update, and delete data properly. These operations are used in almost every website, mobile app, and backend system.
© 2026 MongoDB CRUD Operations Guide. All Rights Reserved.