Courseiva

C100DEV Drivers, Tools, Transactions, and Search Practice Question

A developer needs to run a multi-document transaction using the MongoDB Node.js driver. The transaction must read from the 'orders' collection and write to the 'inventory' collection. Which sequence of operations correctly implements the transaction?

⚠ Common exam trap

The trap here is assuming that the driver provides top-level transaction methods like client.startTransaction() instead of requiring a session-based approach.

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

✓

Start a session with client.startSession(), start a transaction with session.startTransaction(), perform reads and writes with the session option, then commit with session.commitTransaction().

A multi-document transaction in the Node.js driver requires a session. The session must be started, the transaction begun, operations executed with the session passed as an option, and then the transaction committed. Omitting any step, such as not passing the session to operations or not explicitly committing, results in operations not being part of the transaction or the transaction remaining open.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    Start a session with client.startSession(), start a transaction with session.startTransaction(), perform reads and writes with the session option, then commit with session.commitTransaction().

    Why this is correct

    This is the correct sequence for a multi-document transaction in the Node.js driver. You must start a session to associate operations with a transaction, begin the transaction, pass the session to each operation, and finally commit. Aborting on error is also required, but commit is the successful completion step.

  • ✗

    Use a session, start a transaction, perform operations with the session, and rely on automatic commit when the session ends.

    Why it's wrong here

    Transactions do not automatically commit when a session ends. You must explicitly call session.commitTransaction() to commit, or session.abortTransaction() to roll back. Relying on automatic commit would leave the transaction open or cause it to be aborted after a timeout, leading to unexpected behavior.

  • ✗

    Begin a transaction with db.beginTransaction(), run operations on the db object, and call db.commitTransaction().

    Why it's wrong here

    The MongoDB Node.js driver does not expose db.beginTransaction() or db.commitTransaction(). Transactions are session-based. Using the db object without a session will not group operations into a transaction. This approach is invalid and would not provide transactional guarantees.

  • ✗

    Use client.startTransaction() directly, perform operations without a session, and call transaction.commit().

    Why it's wrong here

    The Node.js driver does not provide a client.startTransaction() method. Transactions are managed through a session object. Operations must include the session to be part of the transaction; otherwise, they execute outside the transaction. transaction.commit() is not a valid method; the correct method is session.commitTransaction().

About these practice questions

One of 259 original C100DEV practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.