0
0
MongoDBquery~10 mins

Read from secondaries trade-offs in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read from secondary nodes in MongoDB.

MongoDB
db.collection.find().readPref('[1]')
Drag options to blanks, or click blank then click option'
Aprimary
BprimaryPreferred
Csecondary
Dnearest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'primary' instead of 'secondary' will read only from the primary node.
Using 'nearest' may read from primary or secondary, not guaranteed secondary only.
2fill in blank
medium

Complete the code to set read preference to secondary with a tag in MongoDB.

MongoDB
db.collection.find().readPref('[1]', [{ region: 'us-east' }])
Drag options to blanks, or click blank then click option'
Asecondary
Bprimary
CsecondaryPreferred
Dnearest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'primary' ignores secondary nodes.
Using 'nearest' may read from any node, not guaranteed secondary.
3fill in blank
hard

Fix the error in the read preference setting to read from secondaries.

MongoDB
db.collection.find().readPref('[1]')
Drag options to blanks, or click blank then click option'
Asecondary
Bprimary
CprimaryPreferred
DsecondaryPreferred
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'secondaryPreferred' allows reading from primary if no secondary is available.
Using 'primary' reads only from the primary node.
4fill in blank
hard

Fill both blanks to read from secondaries with a max staleness of 90 seconds.

MongoDB
db.collection.find().readPref('[1]', [], { maxStalenessSeconds: [2] })
Drag options to blanks, or click blank then click option'
Asecondary
Bprimary
C90
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'primary' ignores secondaries.
Setting maxStalenessSeconds too low or too high can cause errors or stale data.
5fill in blank
hard

Fill all three blanks to read from secondaries with tag 'dc:west' and max staleness 120 seconds.

MongoDB
db.collection.find().readPref('[1]', [[2]], { maxStalenessSeconds: [3] })
Drag options to blanks, or click blank then click option'
Asecondary
B{ dc: 'west' }
C120
Dprimary
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'primary' instead of 'secondary' ignores secondaries.
Incorrect tag format causes no matching nodes.
Omitting maxStalenessSeconds allows unlimited staleness.