MongoDB\Client::startSession()
新增自版本1.3.
定义
参数
$options
: array- 一个数组,指定所需的选项。请参阅MongoDB\Driver\Manager::startSession() 扩展的文档中列出了支持的选项。
返回值
一个 MongoDB\Driver\Session 对象。
错误/异常
MongoDB\Driver\Exception\InvalidArgumentException 与扩展级别参数或选项解析相关的错误。
MongoDB\Driver\Exception\RuntimeException 用于扩展级别其他错误(例如连接错误)。
示例
以下示例启动了一个新的会话
$client = new MongoDB\Client; $session = $client->startSession(); var_dump($session);
输出结果将类似于
object(MongoDB\Driver\Session)#2043 (4) { ["logicalSessionId"]=> array(1) { ["id"]=> object(MongoDB\BSON\Binary)#225 (2) { ["data"]=> string(16) "................" ["type"]=> int(4) } } ["clusterTime"]=> NULL ["causalConsistency"]=> bool(true) ["operationTime"]=> NULL }