-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathMongoDBClient-startSession.txt
90 lines (63 loc) · 1.85 KB
/
MongoDBClient-startSession.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
===============================
MongoDB\\Client::startSession()
===============================
.. meta::
:description: Start a new client session with the MongoDB PHP Library and handle potential exceptions.
.. versionadded:: 1.3
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. phpmethod:: MongoDB\Client::startSession()
Start a new client session for use with this client.
.. code-block:: php
function startSession(array $options = []): MongoDB\Driver\Session
Parameters
----------
``$options`` : array
An array specifying the desired options. Refer to the
:php:`MongoDB\Driver\Manager::startSession() <mongodb-driver-manager.startsession>`
extension documentation for a list of supported options.
Return Values
-------------
A :php:`MongoDB\Driver\Session <mongodb-driver-session>` object.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-driver-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Example
-------
The following example starts a new session:
.. code-block:: php
<?php
$client = new MongoDB\Client;
$session = $client->startSession();
var_dump($session);
The output would then resemble:
.. code-block:: none
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
--------
- :php:`MongoDB\Driver\Manager::startSession()
<manual/en/mongodb-driver-manager.startsession.php>`
- :ref:`Causal Consistency <causal-consistency>` in the MongoDB manual