对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。

MongoDB\Client::startSession()

1.3版本新增。

MongoDB\Client::startSession()

启动新的客户端会话以与此客户端一起使用。

function startSession(array $options = []): MongoDB\Driver\Session
$options : array
指定所需选项的大量。有关支持的选项列表,请参阅MongoDB\ 驱动程序\ 经理::startSession() 扩展文档。

MongoDB\ 驱动程序\Session对象。

MongoDB\ 驱动程序\Exception\InvalidArgumentException,用于处理与扩展级别的参数或选项解析相关的错误。

MongoDB\ 驱动程序\Exception\RuntimeException 用于扩展级别的其他错误(例如连接错误)。

以下示例启动一个新会话:

<?php $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}