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
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.