C100DEV Drivers, Tools, Transactions, and Search Practice Question
A developer is writing a Node.js application that must execute a series of document updates across two collections atomically. The application uses the MongoDB Node.js driver and needs to ensure that if any operation fails, all changes are rolled back. Which driver API should the developer use to achieve this?
⚠ Common exam trap
The trap here is assuming that any write method accepting a session parameter automatically participates in a transaction.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use the startSession() method on the MongoClient instance and then call session.withTransaction() to run the operations.
Multi-document transactions in MongoDB are managed through client sessions. The Node.js driver's session.withTransaction() method handles the lifecycle, including retries on transient errors and automatic commit or abort. This ensures that updates across multiple collections are atomic. Other methods like bulkWrite or findOneAndUpdate operate on a single collection or document and lack the necessary transactional guarantees.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use the insertMany() method with the ordered option set to false to ensure atomicity.
Why it's wrong here
insertMany() only inserts documents into a single collection and does not provide cross-collection atomicity. The ordered option controls whether the driver continues after an error, but it does not create a transaction or enable rollback. It is unsuitable for atomic updates across multiple collections as described.
- ✗
Use the bulkWrite() method with ordered: true to group updates across collections.
Why it's wrong here
bulkWrite() only operates on a single collection and does not provide atomicity across multiple collections. Even with ordered: true, it executes operations sequentially but does not offer rollback if a later operation fails. It is not a substitute for multi-document transactions, which are required for cross-collection atomicity.
- ✓
Use the startSession() method on the MongoClient instance and then call session.withTransaction() to run the operations.
Why this is correct
The MongoDB Node.js driver provides startSession() to create a client session, and withTransaction() to run a multi-document transaction with automatic retry and commit/abort handling. This is the correct approach for atomic multi-collection updates in a replica set or sharded cluster, as it ensures all operations either commit together or roll back on error.
- ✗
Use the findOneAndUpdate() method with a session parameter for each update.
Why it's wrong here
Passing a session to findOneAndUpdate() associates the operation with a session but does not automatically group multiple operations into a transaction. Without explicitly starting a transaction and committing it, each findOneAndUpdate() is an independent atomic operation on a single document, and there is no rollback if a subsequent operation fails.
About these practice questions
Courseiva writes every C100DEV question from scratch — 259 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official MongoDB exam blueprint
This C100DEV practice question is part of Courseiva's free MongoDB certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the C100DEV exam.