querydrill

Learn › MongoDB fundamentals

Updating documents

$set, $inc, upsert, replaceOne — and the update that silently deletes fields.

By the end: Change existing documents without destroying the parts you did not mean to touch.

Lessons

6
  1. update() and $set

    MongoDB $set, and the update that silently deletes every other field in your document. The most expensive beginner mistake.

  2. $inc and counters

    MongoDB $inc for atomic counters: increment and decrement a numeric field without reading it first.

  3. Atomicity: why $inc beats read-modify-write

    Single-document writes in MongoDB are atomic. What that guarantee covers, what it does not, and how to use it correctly.

  4. updateOne vs updateMany

    updateOne vs updateMany in MongoDB: which documents each one touches, and why updateOne is the safer default.

  5. replaceOne vs $set

    replaceOne vs $set in MongoDB: one swaps the whole document, the other edits fields. Knowing which you called matters.

  6. Upsert: insert or update

    MongoDB upsert: update a document if it exists, insert it if it does not, in a single atomic operation.

Drills

1 easy · 1 medium · 1 hard
Start reading →Skip to the drills