php8.5
Home/ Manual/ driver / session/ MongoDB\Driver\Session::commitTransaction

MongoDB\Driver\Session::commitTransaction

PHP function Edit on GitHub ✎

(mongodb >=1.5.0)

Commits a transaction

Description

MongoDB\Driver\Session::commitTransaction(): void

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.

Parameters Parameters

Return Values

Void

Errors/Exceptions

  • 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 "UnknownTransactionCommitResult" value, it is safe to re-try the whole transaction. In newer versions of the extension, 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 committed (e.g. a transaction was not started).

See Also

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

Source: reference/mongodb/mongodb/driver/session/committransaction.xml · from the official PHP manual (php/doc-en)