Skip to content

Commit 2aab86a

Browse files
committed
edits
1 parent 857753b commit 2aab86a

File tree

3 files changed

+65
-23
lines changed

3 files changed

+65
-23
lines changed

source/databases-collections.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,8 @@ The following example deletes the ``test_collection`` collection:
187187
Configure Read and Write Operations
188188
-----------------------------------
189189

190-
You can control how the library routes read operations by setting a **read preference**.
191-
You can also control options for how the library waits for acknowledgment of
192-
read and write operations on a replica set by setting a **read concern** and a
193-
**write concern**.
190+
You can control how read and write operations run on replica sets
191+
by specifying a read preference, read concern, and write concern.
194192

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

source/includes/read-write-pref.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$clientOptions = [
1111
'readPreference' => 'secondary',
1212
'readConcernLevel' => 'local',
13-
'w' => 'majority',
13+
'w' => '2',
1414
];
1515

1616
$client = new Client('mongodb://localhost:27017', $clientOptions);
@@ -23,7 +23,7 @@
2323

2424
// start-session-settings
2525
$sessionOptions = [
26-
'readPreference' => new ReadPreference(ReadPreference::RP_SECONDARY),
26+
'readPreference' => new ReadPreference(ReadPreference::PRIMARY_PREFERRED),
2727
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
2828
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY),
2929
];
@@ -33,9 +33,9 @@
3333

3434
// start-transaction-settings
3535
$transactionOptions = [
36-
'readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY),
37-
'readConcern' => new ReadConcern(ReadConcern::AVAILABLE),
38-
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY),
36+
'readPreference' => new ReadPreference(ReadPreference::PRIMARY),
37+
'readConcern' => new ReadConcern(ReadConcern::MAJORITY),
38+
'writeConcern' => new WriteConcern(1),
3939
];
4040

4141
// Start the transaction
@@ -44,8 +44,8 @@
4444

4545
// Sets read and write settings for the "test_database" database
4646
// start-database-settings
47-
$readPreference = new ReadPreference(ReadPreference::RP_PRIMARY_PREFERRED);
48-
$readConcern = new ReadConcern(ReadConcern::LOCAL);
47+
$readPreference = new ReadPreference(ReadPreference::PRIMARY_PREFERRED);
48+
$readConcern = new ReadConcern(ReadConcern::AVAILABLE);
4949
$writeConcern = new WriteConcern(WriteConcern::MAJORITY);
5050

5151
$db = $client->selectDatabase('test_database', [
@@ -57,9 +57,9 @@
5757

5858
// Sets read and write settings for the "test_collection" collection
5959
// start-collection-settings
60-
$readPreference = new ReadPreference(ReadPreference::RP_PRIMARY);
60+
$readPreference = new ReadPreference(ReadPreference::SECONDARY_PREFERRED);
6161
$readConcern = new ReadConcern(ReadConcern::AVAILABLE);
62-
$writeConcern = new WriteConcern(WriteConcern::MAJORITY);
62+
$writeConcern = new WriteConcern(0);
6363

6464
$collection = $client->selectCollection('test_database', 'test_collection', [
6565
'readPreference' => $readPreference,

source/read-write-pref.txt

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ in your replica sets.
4545
Configure Read and Write Operations
4646
-----------------------------------
4747

48+
You can control how the library routes read operations by setting a **read preference**.
49+
You can also control options for how the library waits for acknowledgment of
50+
read and write operations on a replica set by setting a **read concern** and a
51+
**write concern**.
52+
4853
This section shows how to configure the read preference, read concern, and write
4954
concern at various levels by passing an options array parameter to the following
5055
methods:
@@ -84,9 +89,17 @@ In the options parameter, specify the following values:
8489
Client Configuration Example
8590
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8691

87-
The following example shows how to set the read preference, read concern, and
92+
This example shows how to set the read preference, read concern, and
8893
write concern of a ``MongoDB\Client`` instance by passing an array to
89-
the constructor:
94+
the constructor. The code configures the following settings:
95+
96+
- ``secondary`` read preference: Read operations retrieve data from
97+
secondary replica set members
98+
- ``local`` read concern: Read operations return the instance's most recent data
99+
without guaranteeing that the data has been written to a majority of the replica
100+
set members
101+
- ``2`` write concern: The primary and one secondary replica set member
102+
must acknowledge the write operation
90103

91104
.. literalinclude:: /includes/read-write-pref.php
92105
:language: php
@@ -108,9 +121,18 @@ URI, which is passed as a parameter to the ``MongoDB\Client`` constructor:
108121
Session Configuration Example
109122
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110123

111-
The following example shows how to set the read preference, read concern, and
124+
This example shows how to set the read preference, read concern, and
112125
write concern of a session by passing an array to the ``startSession()``
113-
method:
126+
method. The code configures the following settings:
127+
128+
- ``PRIMARY_PREFERRED`` read preference: Read operations retrieve data from
129+
the primary replica set member, or secondary members if the primary is unavailable
130+
- ``LOCAL`` read concern: Read operations return the instance's most recent data
131+
without guaranteeing that the data has been written to a majority of the replica
132+
set members
133+
- ``MAJORITY`` write concern: The majority of all replica set members
134+
must acknowledge the write operation
135+
114136

115137
.. literalinclude:: /includes/read-write-pref.php
116138
:language: php
@@ -123,9 +145,16 @@ method:
123145
Transaction Configuration Example
124146
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125147

126-
The following example shows how to set the read preference, read concern, and
148+
This example shows how to set the read preference, read concern, and
127149
write concern of a transaction by passing an array to the ``startTransaction()``
128-
method:
150+
method. The code configures the following settings:
151+
152+
- ``PRIMARY`` read preference: Read operations retrieve data from
153+
the primary replica set member
154+
- ``MAJORITY`` read concern: Read operations return the instance's most recent data
155+
that has been written to a majority of replica set members
156+
- ``1`` write concern: The primary replica set member must acknowledge the
157+
write operation
129158

130159
.. literalinclude:: /includes/read-write-pref.php
131160
:language: php
@@ -138,9 +167,17 @@ method:
138167
Database Configuration Example
139168
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140169

141-
The following example shows how to set the read preference, read concern, and
170+
This example shows how to set the read preference, read concern, and
142171
write concern of a database called ``test_database`` by passing an options
143-
array to the ``selectDatabase()`` method:
172+
array to the ``selectDatabase()`` method. The code configures the following settings:
173+
174+
- ``PRIMARY_PREFERRED`` read preference: Read operations retrieve data from
175+
the primary replica set member, or secondary members if the primary is unavailable
176+
- ``AVAILABLE`` read concern: Read operations return the instance's most recent data
177+
without guaranteeing that the data has been written to a majority of the replica
178+
set members
179+
- ``MAJORITY`` write concern: The majority of all replica set members
180+
must acknowledge the write operation
144181

145182
.. literalinclude:: /includes/databases-collections/databases-collections.php
146183
:language: php
@@ -153,9 +190,16 @@ array to the ``selectDatabase()`` method:
153190
Collection Configuration Example
154191
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
155192

156-
The following example shows how to set the read preference, read concern, and
193+
This example shows how to set the read preference, read concern, and
157194
write concern of a collection called ``test_collection`` by passing an options
158-
array to the ``selectCollection()`` method:
195+
array to the ``selectCollection()`` method. The code configures the following settings:
196+
197+
- ``SECONDARY_PREFERRED`` read preference: Read operations retrieve data from
198+
secondary replica set members, or the primary members if no secondaries are available
199+
- ``AVAILABLE`` read concern: Read operations return the instance's most recent data
200+
without guaranteeing that the data has been written to a majority of the replica
201+
set members
202+
- ``0`` write concern: Requests no acknowledgment of the write operation
159203

160204
.. literalinclude:: /includes/databases-collections/databases-collections.php
161205
:language: php

0 commit comments

Comments
 (0)