MongoDB\Driver\Session::startTransaction
(mongodb >=1.5.0)
Starts a transaction
Description
Starts a multi-document transaction associated with the session. At any given time, you can have at most one open transaction for a session. After starting a transaction, the session object must be passed to each operation via the "session" option (e.g. MongoDB\Driver\Manager::executeBulkWrite) in order to associate that operation with the transaction.
Transactions can be committed through MongoDB\Driver\Session::commitTransaction, and aborted with MongoDB\Driver\Session::abortTransaction. Transactions are also automatically aborted when the session is closed from garbage collection or by explicitly calling MongoDB\Driver\Session::endSession.
Parameters
optionsOptions can be passed as argument to this method. Each element in this options array overrides the corresponding option from the
"defaultTransactionOptions"option, if set when starting the session withMongoDB\Driver\Manager::startSession.Option Type Description
Return Values
Void
Errors/Exceptions
- Throws
MongoDB\Driver\Exception\CommandExceptionif the transaction could not be started because of a server-side problem (e.g. a lock could not be obtained). - Throws
MongoDB\Driver\Exception\RuntimeExceptionif the transaction could not be started (e.g. a transaction was already started).
Changelog
| Version | Description |
|---|---|
| PECL mongodb 1.6.0 | The "maxCommitTimeMS" option was added. |
See Also
MongoDB\Driver\Manager::startSessionMongoDB\Driver\Session::commitTransactionMongoDB\Driver\Session::abortTransaction