Problem Statement
Which read preference directs read operations to secondary nodes only?
Explanation
The secondary read preference directs all read operations to secondary nodes only, never to the primary. This is useful for distributing read load away from the primary, which handles all writes.
However, reads from secondaries may return stale data because there is replication lag. Other read preferences include primary for reading from primary only, primaryPreferred to read from primary if available or secondary otherwise, secondaryPreferred to read from secondary if available or primary otherwise, and nearest to read from the lowest latency node.
Code Solution
SolutionRead Only
// Set read preference to secondary
db.users.find().readPref("secondary")
// In connection string
mongo "mongodb://host1,host2,host3/?replicaSet=myRS&readPreference=secondary"
// With tags for specific secondaries
db.users.find().readPref(
"secondary",
[{ datacenter: "east" }]
)