Docs Menu

Docs HomePHP Library Manual

MongoDB\Client::startSession()

On this page

  • Definition
  • Parameters
  • Return Values
  • Errors/Exceptions
  • Example
  • See Also

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 driver level.

MongoDB\Driver\Exception\RuntimeException for other errors at the driver 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
}
←  MongoDB\Client::selectDatabase()MongoDB\Client::watch() →