MongoDB\Driver\Manager::startSession
(mongodb >=1.4.0)
MongoDB\Driver\Manager::startSession — Start a new client session for use with this client
说明
$options
= ?): MongoDB\Driver\SessionCreates a MongoDB\Driver\Session for the given options. The session may then be specified when executing commands, queries, and write operations.
注意: A MongoDB\Driver\Session can only be used with the MongoDB\Driver\Manager from which it was created.
参数
-
options
-
options Option Type Description Default causalConsistency bool Configure causal consistency in a session. If
true
, each operation in the session will be causally ordered after the previous read or write operation. Set tofalse
to disable causal consistency.See » Casual Consistency in the MongoDB manual for more information.
true
defaultTransactionOptions array Default options to apply to newly created transactions. These options are used unless they are overridden when a transaction is started with different value for each option.
options Option Type Description maxCommitTimeMS integer The maximum amount of time in milliseconds to allow a single
commitTransaction
command to run.If specified,
maxCommitTimeMS
must be a signed 32-bit integer greater than or equal to zero.readConcern MongoDB\Driver\ReadConcern A read concern to apply to the operation.
This option is available in MongoDB 3.2+ and will result in an exception at execution time if specified for an older server version.
readPreference MongoDB\Driver\ReadPreference A read preference to use for selecting a server for the operation.
writeConcern MongoDB\Driver\WriteConcern A write concern to apply to the operation.
This option is available in MongoDB 4.0+.
[]
snapshot bool Configure snapshot reads in a session. If
true
, a timestamp will be obtained from the first supported read operation in the session (i.e.find
,aggregate
, or unshardeddistinct
). Subsequent read operations within the session will then utilize a"snapshot"
read concern level to read majority-committed data from that timestamp. Set tofalse
to disable snapshot reads.Snapshot reads require MongoDB 5.0+ and cannot be used with causal consistency, transactions, or write operations. If
"snapshot"
istrue
,"causalConsistency"
will default tofalse
.See » Read Concern "snapshot" in the MongoDB manual for more information.
false
返回值
Returns a MongoDB\Driver\Session.
错误/异常
- Throws MongoDB\Driver\Exception\InvalidArgumentException on argument parsing errors.
- Throws MongoDB\Driver\Exception\InvalidArgumentException if the
"causalConsistency"
and"snapshot"
options are bothtrue
. - Throws MongoDB\Driver\Exception\RuntimeException if the session could not be created (e.g. libmongoc does not support crypto).
更新日志
版本 | 说明 |
---|---|
PECL mongodb 1.11.0 |
The |
PECL mongodb 1.6.0 |
The |
PECL mongodb 1.5.0 |
The |
参见
- MongoDB\Driver\Session
- » Casual Consistency in the MongoDB manual

User Contributed Notes
备份地址:http://www.lvesu.com/blog/php/mongodb-driver-manager.startsession.php