MongoDB\Client::startSession()

For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

MongoDB\Client::startSession()

New in version 1.3

Definition

Start a new client session for use with this client.

function startSession(array $options = []): MongoDB\Driver\Session

Parameters

$options : array

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

Return Values

A MongoDB\Driver\Session object.

Errors/Exceptions

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).

Example

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
}

See Also

  • MongoDB\Driver\Manager::startSession()

  • [Causal Consistency](https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency.md#std-label-causal-consistency in the MongoDB manual