Skip to content

Commit a36917d

Browse files
committed
RR feedback
1 parent 79e3608 commit a36917d

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

source/databases-collections.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Configure Read and Write Operations
188188
-----------------------------------
189189

190190
You can control how read and write operations run on replica sets
191-
by specifying a read preference, read concern, and write concern.
191+
by specifying a read preference, read concern, or write concern.
192192

193193
By default, databases inherit read and write settings from the ``MongoDB\Client``
194194
instance. Collections inherit these settings from the ``MongoDB\Client`` or

source/includes/read-write-pref.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,24 @@
3838
'writeConcern' => new WriteConcern(1),
3939
];
4040

41-
// Start the transaction
4241
$session->startTransaction($transactionOptions);
4342
// end-transaction-settings
4443

4544
// Sets read and write settings for the "test_database" database
4645
// start-database-settings
47-
$readPreference = new ReadPreference(ReadPreference::PRIMARY_PREFERRED);
48-
$readConcern = new ReadConcern(ReadConcern::AVAILABLE);
49-
$writeConcern = new WriteConcern(WriteConcern::MAJORITY);
50-
5146
$db = $client->selectDatabase('test_database', [
52-
'readPreference' => $readPreference,
53-
'readConcern' => $readConcern,
54-
'writeConcern' => $writeConcern,
47+
'readPreference' => new ReadPreference(ReadPreference::PRIMARY_PREFERRED),
48+
'readConcern' => new ReadConcern(ReadConcern::AVAILABLE),
49+
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY),
5550
]);
5651
// end-database-settings
5752

5853
// Sets read and write settings for the "test_collection" collection
5954
// start-collection-settings
60-
$readPreference = new ReadPreference(ReadPreference::SECONDARY_PREFERRED);
61-
$readConcern = new ReadConcern(ReadConcern::AVAILABLE);
62-
$writeConcern = new WriteConcern(0);
63-
6455
$collection = $client->selectCollection('test_database', 'test_collection', [
65-
'readPreference' => $readPreference,
66-
'readConcern' => $readConcern,
67-
'writeConcern' => $writeConcern,
56+
'readPreference' => new ReadPreference(ReadPreference::SECONDARY_PREFERRED),
57+
'readConcern' => new ReadConcern(ReadConcern::AVAILABLE),
58+
'writeConcern' => new WriteConcern(0),
6859
]);
6960

7061
// end-collection-settings
@@ -98,5 +89,5 @@
9889
'localThresholdMS' => 35,
9990
];
10091

101-
$client = new Client('<connection string>', [], $options);
92+
$client = new Client('mongodb://localhost:27017', [], $options);
10293
// end-local-threshold

source/read-write-pref.txt

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Specify How CRUD Operations Run on Replica Sets
2020
Overview
2121
--------
2222

23-
In this guide, you can learn how to use the **write concern**, **read concern**, and
24-
**read preference** configurations to modify the way that MongoDB runs
25-
create, read, update, and delete (CRUD) operations on replica sets.
23+
In this guide, you can learn how to configure **write concern**, **read concern**,
24+
and **read preference** options to modify the way that the {+php-library+} runs create,
25+
read, update, and delete (CRUD) operations on replica sets.
2626

2727
You can set write concern, read concern, and read preference options at the following
2828
levels:
@@ -35,10 +35,15 @@ levels:
3535

3636
This list also indicates the increasing order of precedence of the option settings. For
3737
example, if you set a read concern level for a transaction, it will override a read
38-
concern level set for the client.
38+
concern level inherited from the client.
3939

4040
These options allow you to customize the causal consistency and availability of the data
41-
in your replica sets.
41+
in your replica sets. To see a full list of read preference, read concern, and write concern
42+
options, see the following guides in the {+mdb-server+} manual:
43+
44+
- :manual:`Read Preference </core/read-preference/>`
45+
- :manual:`Read Concern </reference/read-concern/>`
46+
- :manual:`Write Concern </reference/write-concern/>`
4247

4348
.. _php-read-write-config:
4449

@@ -47,11 +52,11 @@ Configure Read and Write Operations
4752

4853
You can control how the library routes read operations by setting a read preference.
4954
You can also control how the library waits for acknowledgment of read and write operations
50-
on a replica set by setting a read and write concern.
55+
on a replica set by setting read and write concerns.
5156

5257
This section shows how to configure the read preference, read concern, and write
53-
concern at various levels by passing an options array parameter to the following
54-
methods:
58+
concern at various levels by passing an options array parameter to any one of the
59+
following methods:
5560

5661
- :ref:`MongoDB\Client::__construct() <php-read-write-client>`: Configures client-level
5762
settings
@@ -96,6 +101,14 @@ URI, which is passed as a parameter to the ``MongoDB\Client`` constructor:
96101
:start-after: start-client-settings-uri
97102
:end-before: end-client-settings-uri
98103

104+
.. note::
105+
106+
The ``readPreference``, ``readConcernLevel``, and ``w`` client options accept
107+
string values. When configuring read and write settings at any other level,
108+
you must assign values of type ``MongoDB\Driver\ReadPreference``,
109+
``MongoDB\Driver\ReadConcern``, and ``MongoDB\Driver\WriteConcern`` to the corresponding
110+
options.
111+
99112
.. _php-read-write-session:
100113

101114
Session Configuration
@@ -113,7 +126,6 @@ method. The code configures the following settings:
113126
- ``MAJORITY`` write concern: The majority of all replica set members
114127
must acknowledge the write operation
115128

116-
117129
.. literalinclude:: /includes/read-write-pref.php
118130
:language: php
119131
:dedent:
@@ -203,7 +215,7 @@ settings in the following ways:
203215
Tag Sets
204216
~~~~~~~~
205217

206-
In {+mdb-server+}, you can apply key-value :manual:`tags
218+
The {+mdb-server+} allows you to apply key-value :manual:`tags
207219
</core/read-preference-tags/>` to replica-set
208220
members according to any criteria you choose. You can then use
209221
those tags to target one or more members for a read operation.
@@ -214,19 +226,20 @@ pass them as a parameter to your ``MongoDB\Driver\ReadPreference`` class
214226
constructor. Then, set the ``MongoDB\Driver\ReadPreference`` object as
215227
the value of the ``readPreference`` database option.
216228

217-
This code example sets the ``readPreference`` option to a tag set
218-
that instructs ``test_database`` to prefer reads from secondary replica set
219-
members in the following order:
229+
Suppose you are connected to a replica set that contains members hosted
230+
at multiple data centers across the United States. This code example sets
231+
the ``readPreference`` option to a tag set that instructs ``test_database``
232+
to prefer reads from secondary replica set members in the following order:
220233

221234
1. Members from the New York data center (``['dc' => 'ny']``)
222235
#. Members from the San Francisco data center (``['dc' => 'sf']``)
223236
#. Any secondary members (``[]``)
224237

225238
.. literalinclude:: /includes/databases-collections/databases-collections.php
226-
:language: php
227-
:dedent:
228-
:start-after: start-tag-set
229-
:end-before: end-tag-set
239+
:language: php
240+
:dedent:
241+
:start-after: start-tag-set
242+
:end-before: end-tag-set
230243

231244
.. _php-local-threshold:
232245

0 commit comments

Comments
 (0)