Navigation

commitTransaction

On this page

Definition

commitTransaction

New in version 4.0.

Saves the changes made by the operations in the multi-document transaction and ends the transaction. Until the commit, none of the data changes made from within the transaction are visible outside the transaction.

To run the commitTransaction, the command must be run against the admin database and run within a Session. Rather than run the commitTransaction command directly, most users should use the driver method or the mongo shell Session.commitTransaction() helper.

The command has the following syntax:

{
  commitTransaction: 1,
  txnNumber: <long>,
  writeConcern: <document>,
  autocommit: false
 }

Behavior

Write Concern

When committing the transaction, the session uses the write concern specified at the transaction start. See Session.startTransaction().

If you commit using "w: 1" write concern, your transaction can be rolled back if there is a failover..

Atomicity

When a transaction commits, all data changes made in the transaction are saved and visible outside the transaction.