MongoDB\Driver\Session::commitTransaction

Commits a transaction

&reftitle.description; final public `void` `MongoDB\Driver\Session::commitTransaction`

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.

&reftitle.parameters; &no.function.parameters;
&reftitle.returnvalues;

&return.void;

&reftitle.errors;

&mongodb.throws.argumentparsing;
- Throws `MongoDB\Driver\Exception\CommandException` if the server could not commit the transaction (e.g. due to conflicts, network issues). In case the exception's `MongoDB\Driver\Exception\CommandException::getResultDocument` has a `"errorLabels"` element, and this array contains a `"TransientTransactionError"` or `"UnUnknownTransactionCommitResult"` value, it is safe to re-try the whole transaction. In newer versions of the driver, `MongoDB\Driver\Exception\RuntimeException::hasErrorLabel` should be used to test for this situation instead.
- Throws `MongoDB\Driver\Exception\RuntimeException` if the transaction could not be commited (e.g. a transaction was not started).

&reftitle.seealso;

- `MongoDB\Driver\Manager::startSession`
- `MongoDB\Driver\Session::abortTransaction`
- `MongoDB\Driver\Session::startTransaction`
- `MongoDB\Driver\Exception\RuntimeException::hasErrorLabel`