@@ -47,13 +47,18 @@ Configure Read and Write Operations
47
47
48
48
This section shows how to configure the read preference, read concern, and write
49
49
concern at various levels by passing an options array parameter to the following
50
- objects and methods:
51
-
52
- - :ref:`MongoDB\\Client <php-read-write-client>`
53
- - :ref:`MongoDB\\Driver\\Session <php-read-write-session>`
54
- - :ref:`MongoDB\\with_transaction() <php-read-write-transaction>`
55
- - :ref:`MongoDB\\Database <php-read-write-database>`
56
- - :ref:`MongoDB\\Collection <php-read-write-collection>`
50
+ methods:
51
+
52
+ - :ref:`MongoDB\\Client::__construct() <php-read-write-client>`: Configures read
53
+ and write settings at the client level
54
+ - :ref:`MongoDB\\Client::startSession() <php-read-write-session>`: Configures read
55
+ and write settings at the session level
56
+ - :ref:`MongoDB\\Driver\\Session::startTransaction() <php-read-write-transaction>`:
57
+ Configures read and write settings at the transaction level
58
+ - :ref:`MongoDB\\Client::selectDatabase() <php-read-write-database>`: Configures read
59
+ and write settings at the database level
60
+ - :ref:`MongoDB\\Client::selectCollection() <php-read-write-collection>`: Configures read
61
+ and write settings at the collection level
57
62
58
63
In the options parameter, specify the following values:
59
64
@@ -67,6 +72,13 @@ In the options parameter, specify the following values:
67
72
concerns, see :php:`MongoDB\Driver\WriteConcern <mongodb-driver-writeconcern>`
68
73
in the extension API documentation.
69
74
75
+ .. note::
76
+
77
+ When setting a write concern at the ``MongoDB\Client`` level, specify the ``w``
78
+ value in an options array rather than ``writeConcern.`` You can also specify
79
+ read and write settings in the connection URI. For more information,
80
+ see the :ref:`php-read-write-client`.
81
+
70
82
.. _php-read-write-client:
71
83
72
84
Client Configuration Example
@@ -76,30 +88,59 @@ The following example shows how to set the read preference, read concern, and
76
88
write concern of a ``MongoDB\Client`` instance by passing an array to
77
89
the constructor:
78
90
79
- .. literalinclude:: /includes/databases-collections/databases-collections .php
91
+ .. literalinclude:: /includes/read-write-pref .php
80
92
:language: php
81
93
:dedent:
82
- :start-after: start-database-settings
83
- :end-before: end-database-settings
94
+ :start-after: start-client-settings
95
+ :end-before: end-client-settings
96
+
97
+ Alternatively, you can specify the read and write settings in the connection
98
+ URI, which is passed as a parameter to the ``MongoDB\Client`` constructor:
99
+
100
+ .. literalinclude:: /includes/read-write-pref.php
101
+ :language: php
102
+ :dedent:
103
+ :start-after: start-client-settings-uri
104
+ :end-before: end-client-settings-uri
84
105
85
106
.. _php-read-write-session:
86
107
87
108
Session Configuration Example
88
109
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89
110
111
+ The following example shows how to set the read preference, read concern, and
112
+ write concern of a session by passing an array to the ``startSession()``
113
+ method:
114
+
115
+ .. literalinclude:: /includes/read-write-pref.php
116
+ :language: php
117
+ :dedent:
118
+ :start-after: start-session-settings
119
+ :end-before: end-session-settings
120
+
90
121
.. _php-read-write-transaction:
91
122
92
123
Transaction Configuration Example
93
124
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94
125
126
+ The following example shows how to set the read preference, read concern, and
127
+ write concern of a transaction by passing an array to the ``startTransaction()``
128
+ method:
129
+
130
+ .. literalinclude:: /includes/read-write-pref.php
131
+ :language: php
132
+ :dedent:
133
+ :start-after: start-transaction-settings
134
+ :end-before: end-transaction-settings
135
+
95
136
.. _php-read-write-database:
96
137
97
138
Database Configuration Example
98
139
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99
140
100
141
The following example shows how to set the read preference, read concern, and
101
142
write concern of a database called ``test_database`` by passing an options
102
- array to ``selectDatabase()``:
143
+ array to the ``selectDatabase()`` method :
103
144
104
145
.. literalinclude:: /includes/databases-collections/databases-collections.php
105
146
:language: php
@@ -114,19 +155,29 @@ Collection Configuration Example
114
155
115
156
The following example shows how to set the read preference, read concern, and
116
157
write concern of a collection called ``test_collection`` by passing an options
117
- array to ``selectCollection()``:
158
+ array to the ``selectCollection()`` method :
118
159
119
160
.. literalinclude:: /includes/databases-collections/databases-collections.php
120
161
:language: php
121
162
:dedent:
122
163
:start-after: start-collection-settings
123
164
:end-before: end-collection-settings
124
165
166
+ .. _php-read-write-advanced:
167
+
125
168
Advanced Read Configurations
126
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169
+ ----------------------------
170
+
171
+ This section shows how to further customize your read operation
172
+ settings in the following ways:
173
+
174
+ - :ref:`Apply a tag set <php-tag-sets>`
175
+ - :ref:`Specify a local threshold <php-local-threshold>`
176
+
177
+ .. _php-tag-sets:
127
178
128
179
Tag Sets
129
- ````````
180
+ ~~~~~~~~
130
181
131
182
In {+mdb-server+}, you can apply key-value :manual:`tags
132
183
</core/read-preference-tags/>` to replica-set
@@ -153,8 +204,10 @@ members in the following order:
153
204
:start-after: start-tag-set
154
205
:end-before: end-tag-set
155
206
207
+ .. _php-local-threshold:
208
+
156
209
Local Threshold
157
- ```````````````
210
+ ~~~~~~~~~~~~~~~
158
211
159
212
If multiple replica-set members match the read preference and tag sets you specify,
160
213
the {+php-library+} reads from the nearest replica-set members, chosen according to
@@ -198,4 +251,10 @@ API Documentation
198
251
~~~~~~~~~~~~~~~~~
199
252
200
253
To learn more about any of the methods or types discussed in this
201
- guide, see the following API documentation:
254
+ guide, see the following API documentation:
255
+
256
+ - :phpmethod:`MongoDB\Client::__construct()`
257
+ - :phpmethod:`MongoDB\Client::startSession()`
258
+ - :php:`MongoDB\Driver\Session::startTransaction()`
259
+ - :phpmethod:`MongoDB\Client::selectDatabase()`
260
+ - :phpmethod:`MongoDB\Client::selectCollection()`
0 commit comments