大网数据广告活动
PHP 语言与运行手册

MongoDB\Driver\Manager::startSession · Start a new client session for use with this client

· 52CE 我爱测

MongoDB\Driver\Manager::startSession — Start a new client session for use with this client

MongoDB\Driver\Manager::startSession

(mongodb >=1.4.0)

MongoDB\Driver\Manager::startSession — Start a new client session for use with this client

Description

final public function MongoDB\Driver\Manager::startSession(?array $options = null): MongoDB\Driver\Session

Creates a MongoDB\Driver\Session for the given options. The session may then be specified when executing commands, queries, and write operations.

Note:

A MongoDB\Driver\Session can only be used with the MongoDB\Driver\Manager from which it was created.

Parameters

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 to false to disable causal consistency. See » Causal 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 unsharded distinct). Subsequent read operations within the session will then utilize a "snapshot" read concern level to read majority-committed data from that timestamp. Set to false to disable snapshot reads. Snapshot reads require MongoDB 5.0+ and cannot be used with causal consistency, transactions, or write operations. If "snapshot" is true, "causalConsistency" will default to false. See » Read Concern "snapshot" in the MongoDB manual for more information. false

Return Values

Returns a MongoDB\Driver\Session.

Errors/Exceptions

Changelog

Version Description
PECL mongodb 1.11.0 The "snapshot" option was added.
PECL mongodb 1.6.0 The "maxCommitTimeMS" option was added to "defaultTransactionOptions".
PECL mongodb 1.5.0 The "defaultTransactionOptions" option was added.

See Also

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。