- Reference >
- JavaScript Methods >
- cursor.readPref()
cursor.readPref()¶
-
cursor.
readPref
()¶ Parameters: - mode (string) – Read preference mode
- tagSet (array) – Optional. Array of tag set objects
Append the
readPref()
to a cursor to control how the client will route the query will route to members of the replica set.The
mode
string should be one of:The
tagSet
parameter, if given, should consist of an array of tag set objects for filtering secondary read operations. For example, a secondary member tagged{ dc: 'ny', rack: 2, size: 'large' }
will match the tag set{ dc: 'ny', rack: 2 }
. Clients match tag sets first in the order they appear in the read preference specification. You may specify an empty tag set{}
as the last element to default to any available secondary. See the tag sets documentation for more information.Note
You must apply
cursor.readPref()
to the cursor before retrieving any documents from the database.