Skip to content
Justice Tech School

Transactions Intro

Multi document transactions need a replica set.

Example
const session = client.startSession();
await session.withTransaction(async () => {
  await a.updateOne({ _id: 1 }, { $inc: { bal: -10 } }, { session });
  await b.updateOne({ _id: 2 }, { $inc: { bal: 10 } }, { session });
});

Exercise

Session.

client.start()

Quiz Test

What do transactions guarantee?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.