- Reference >
- Database Commands >
- Sessions Commands >
- commitTransaction
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 theadmin
database and run within aSession
. Rather than run thecommitTransaction
command directly, most users should use the driver method or themongo
shellSession.commitTransaction()
helper.The command has the following syntax:
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.