Insert, Find, Update, Delete, and Core CRUD Operations
Master everyday MongoDB CRUD operations and understand how applications map business actions to document changes.
Inside this chapter
- CRUD as the Core of Application Work
- Inserting Documents
- Finding Documents
- Updating and Deleting Documents
Series navigation
Study the chapters in order for the clearest path from MongoDB basics to advanced document modeling and production operations. Use the navigation at the bottom of each page to move through the full series.
CRUD as the Core of Application Work
Most applications repeatedly create documents, retrieve data for pages and APIs, update selected fields, and delete or archive records that are no longer needed. MongoDB’s CRUD model is simple to begin with, but advanced usage depends on understanding update operators, filters, and document shapes clearly.
Inserting Documents
db.users.insertOne({
fullName: "Rohan Iyer",
email: "rohan@example.com",
isActive: true,
createdAt: new Date()
}) Finding Documents
db.users.find(
{ isActive: true },
{ fullName: 1, email: 1 }
)
The first object filters the result. The second object projects which fields should be returned. Beginners should learn that fetching only required fields is a good habit.
Updating and Deleting Documents
db.users.updateOne(
{ email: "rohan@example.com" },
{ $set: { isActive: false } }
)
db.users.deleteOne({ email: "olduser@example.com" })