0Pricing
MongoDB Academy · Lesson

Read Preferences: Distributing Read Load

Learners will configure primary, primaryPreferred, secondary, nearest, and tagged read preferences to route reads across the replica set.

What Is a Read Preference?

A read preference controls which replica set member the driver sends read operations to. By default, all reads go to the primary to ensure you always see the latest data. However, redirecting reads to secondaries can reduce load on the primary and bring reads geographically closer to users — at the cost of potentially reading slightly stale data.

primary: Always Read From Primary

primary (the default) routes every read to the primary. This guarantees strong consistency — you will always read your own writes and see the most up-to-date data. The downside is that the primary handles all read and write traffic. Use this mode whenever stale data would be unacceptable, such as in financial applications or user-facing dashboards.

// Explicit primary read preference (this is the default)
const col = db.collection('accounts', {
  readPreference: 'primary'
})
await col.findOne({ _id: userId })

All lessons in this course

  1. Replica Set Members: Primary, Secondary, Arbiter
  2. Elections and Automatic Failover
  3. Write Concerns and Acknowledged Durability
  4. Read Preferences: Distributing Read Load
← Back to MongoDB Academy