But it still reads from the primary. What is the likely cause?
medium
A. The query must specify a filter to use read preference
B. The syntax for setting read preference is incorrect
C. No secondary members are available, so it falls back to primary
D. Read preference only works for writes
Solution
Step 1: Understand 'secondaryPreferred' behavior
This mode reads from secondary if available; otherwise, it falls back to primary.
Step 2: Reason why primary is used
If no secondary is available or reachable, the driver reads from primary as fallback.
Final Answer:
No secondary members are available, so it falls back to primary -> Option C
Quick Check:
'secondaryPreferred' falls back to primary if no secondary [OK]
Hint: 'secondaryPreferred' falls back to primary if no secondary [OK]
Common Mistakes:
Thinking syntax is wrong when it is correct
Believing read preference needs a filter
Confusing read preference with write behavior
5. You want to optimize read performance by reading from secondaries but ensure data is fresh enough. Which read preference mode should you choose?
hard
A. secondaryPreferred
B. nearest
C. primary
D. secondary
Solution
Step 1: Understand read preference modes
primary reads only from primary (fresh but may be slower), secondary reads only from secondaries (may be stale), secondaryPreferred reads secondaries or falls back to primary, nearest reads from the closest member regardless of type.
Step 2: Balance freshness and performance
secondaryPreferred prefers secondaries for read performance optimization but falls back to the primary to ensure data freshness and availability.