MongoDB Foundations·Documents with discipline

CRUD that stays predictable

Insert, read, update and delete with explicit filters and deliberate write concerns.

Beginner 14 min read Lesson 7 of 300 Challenge included
What you will be able to do
  • Use updateOne with a precise filter to avoid accidental mass updates.
  • Use $set and $unset rather than a full replacement.
  • Choose write concern based on durability requirements.

In plain English

Filters select documents; update operators change only named fields. Use $set instead of replacing a whole document when you mean to change one field. Write concern decides how durable a write must be before it is acknowledged.

crud.jsJavaScript
db.lessons.insertOne({ slug: "queries", minutes: 14 });

db.lessons.updateOne(
  { slug: "queries" },
  { $set: { published: true }, $inc: { version: 1 } }
);

db.lessons.deleteOne({ slug: "queries", published: false });
Your turn

Publish a lesson

Easy

Update the lesson with slug "queries" to published: true and increment its version by one.

JAVASCRIPT · starter
db.lessons.updateOne({ slug: "queries" }, {})
Check your understanding before moving on.
Knowledge checkQuestion 1

Which operator changes a single field without replacing the document?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 7 of 300 · 0% of course