For AI agents: a documentation index is available at https://www.mongodb.com/pt-br/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

MongoDB\Client::startSession()

New in version 1.3. :

MongoDB\Client::startSession()

Start a new client session for use with this client.

function startSession(array $options = []): MongoDB\Driver\Session
$options : array
An array specifying the desired options. Refer to the MongoDB\Driver\Manager::startSession() extension documentation for a list of supported options.

A MongoDB\Driver\Session object.

MongoDB\Driver\Exception\InvalidArgumentException for errors related to the parsing of parameters or options at the extension level.

MongoDB\Driver\Exception\RuntimeException for other errors at the extension level (e.g. connection errors).

The following example starts a new session:

<?php
$client = new MongoDB\Client;
$session = $client->startSession();
var_dump($session);

The output would then resemble:

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
}