Skip to content

Commit 042f87b

Browse files
(DOCSP-15892): Read preference difference between mongosh and mongo (#107)
* (DOCSP-15892): Read preference difference between mongosh and mongo * Tweaks per feedback * typo * reorder
1 parent 69d9dc3 commit 042f87b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

source/reference/compatibility.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,44 @@ the methods listed in the :guilabel:`Alternative Methods` column.
5252
- :method:`db.collection.findOneAndUpdate()`
5353
- :method:`db.collection.bulkWrite()`
5454

55+
Read Preference Behavior
56+
------------------------
57+
58+
Read Operations on a Secondary Node
59+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60+
61+
When using ``mongosh`` to connect directly to a :term:`secondary`
62+
replica set member, you do not have to explicitly enable secondary reads
63+
with ``rs.secondaryOk()``.
64+
65+
You can read from a secondary member if you specify a
66+
:manual:`read preference </core/read-preference/>` of either:
67+
68+
- :readmode:`primaryPreferred`
69+
- :readmode:`secondary`
70+
- :readmode:`secondaryPreferred`
71+
72+
To specify a read preference, you can use either:
73+
74+
- The :urioption:`readPreference` connection string option when
75+
connecting to the node.
76+
77+
- The :method:`Mongo.setReadPref()` method.
78+
79+
The legacy ``mongo`` shell required running ``rs.secondaryOk()`` to
80+
enable secondary reads.
81+
82+
``show`` Helper Methods
83+
~~~~~~~~~~~~~~~~~~~~~~~
84+
85+
The following ``show`` helper methods always use a read preference of
86+
``primaryPreferred``, even when a different read preference has been
87+
specified for the operation:
88+
89+
- ``show dbs``
90+
- ``show databases``
91+
- ``show collections``
92+
- ``show tables``
93+
94+
In the legacy ``mongo`` shell, these operations use the specified read
95+
preference.

0 commit comments

Comments
 (0)