@@ -193,10 +193,8 @@ The following example deletes the ``test_collection`` collection:
193193Configure Read and Write Operations
194194-----------------------------------
195195
196- You can control how the library routes read operations by setting a **read preference**.
197- You can also control options for how the library waits for acknowledgment of
198- read and write operations on a replica set by setting a **read concern** and a
199- **write concern**.
196+ You can control how read and write operations run on replica sets
197+ by specifying a read preference, read concern, or write concern.
200198
201199By default, databases inherit read and write settings from the ``MongoDB\Client``
202200instance. Collections inherit these settings from the ``MongoDB\Client`` or
@@ -205,114 +203,8 @@ You can change these settings by passing an options array to the
205203``MongoDB\Client::selectDatabase()``, ``MongoDB\Client::selectCollection()``, or
206204``MongoDB\Database::selectCollection()`` methods.
207205
208- To change the read preference, read concern, and write concern of your database
209- or collection, set the following options in the array parameter:
210-
211- - ``readPreference``: Sets the read preference. For a list of available read
212- preferences, see :php:`MongoDB\Driver\ReadPreference <mongodb-driver-readpreference>`
213- in the extension API documentation.
214- - ``readConcern``: Sets the read concern. For a list of available read
215- concerns, see :php:`MongoDB\Driver\ReadConcern <mongodb-driver-readconcern>`
216- in the extension API documentation.
217- - ``writeConcern``: Sets the write concern. For a list of available write
218- concerns, see :php:`MongoDB\Driver\WriteConcern <mongodb-driver-writeconcern>`
219- in the extension API documentation.
220-
221- .. tip::
222-
223- To learn more about read preferences and read and write concerns, see the
224- following guides in the MongoDB Server manual:
225-
226- - :manual:`Read Preference </core/read-preference/>`
227- - :manual:`Read Concern </reference/read-concern/>`
228- - :manual:`Write Concern </reference/write-concern/>`
229-
230- Database Configuration Example
231- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232-
233- The following example shows how to set the read preference, read concern, and
234- write concern of a database called ``test_database`` by passing an options
235- array to ``selectDatabase()``:
236-
237- .. literalinclude:: /includes/databases-collections/databases-collections.php
238- :language: php
239- :dedent:
240- :start-after: start-database-settings
241- :end-before: end-database-settings
242-
243- Collection Configuration Example
244- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
245-
246- The following example shows how to set the read preference, read concern, and
247- write concern of a collection called ``test_collection`` by passing an options
248- array to ``selectCollection()``:
249-
250- .. literalinclude:: /includes/databases-collections/databases-collections.php
251- :language: php
252- :dedent:
253- :start-after: start-collection-settings
254- :end-before: end-collection-settings
255-
256- Advanced Read Configurations
257- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
258-
259- Tag Sets
260- ````````
261-
262- In {+mdb-server+}, you can apply key-value :manual:`tags
263- </core/read-preference-tags/>` to replica-set
264- members according to any criteria you choose. You can then use
265- those tags to target one or more members for a read operation.
266-
267- By default, the {+php-library+} ignores tags when choosing a member
268- to read from. To instruct the {+php-library+} to prefer certain tags,
269- pass them as a parameter to your ``MongoDB\Driver\ReadPreference`` class
270- constructor. Then, set the ``MongoDB\Driver\ReadPreference`` object as
271- the value of the ``readPreference`` database option.
272-
273- This code example sets the ``readPreference`` option to a tag set
274- that instructs ``test_database`` to prefer reads from secondary replica set
275- members in the following order:
276-
277- 1. Members from the New York data center (``['dc' => 'ny']``)
278- #. Members from the San Francisco data center (``['dc' => 'sf']``)
279- #. Any secondary members (``[]``)
280-
281- .. literalinclude:: /includes/databases-collections/databases-collections.php
282- :language: php
283- :dedent:
284- :start-after: start-tag-set
285- :end-before: end-tag-set
286-
287- Local Threshold
288- ```````````````
289-
290- If multiple replica-set members match the read preference and tag sets you specify,
291- the {+php-library+} reads from the nearest replica-set members, chosen according to
292- their ping time.
293-
294- By default, the library uses only members whose ping times are within 15 milliseconds
295- of the nearest member for queries. To distribute reads between members with
296- higher latencies, pass an options array to the ``MongoDB\Client`` constructor that
297- sets the ``localThresholdMS`` option.
298-
299- The following example specifies a local threshold of 35 milliseconds:
300-
301- .. literalinclude:: /includes/databases-collections/databases-collections.php
302- :language: php
303- :dedent:
304- :start-after: start-local-threshold
305- :end-before: end-local-threshold
306-
307- In the preceding example, the {+php-library+} distributes reads among matching members
308- within 35 milliseconds of the closest member's ping time.
309-
310- .. note::
311-
312- The {+php-library+} ignores the value of ``localThresholdMS`` when communicating with a
313- replica set through a ``mongos`` instance. In this case, use the
314- :manual:`localThreshold </reference/program/mongos/#std-option-mongos.--localThreshold>`
315- command-line option.
206+ To learn more about setting a read preference, read concern, and write concern,
207+ see the :ref:`php-read-write-pref` guide.
316208
317209API Documentation
318210-----------------
0 commit comments