0
0
MongoDBquery~10 mins

Tuning consistency vs performance in MongoDB - Interactive Practice

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

Complete the code to set the read concern level to 'majority' for stronger consistency.

MongoDB
db.collection.find().readConcern('[1]')
Drag options to blanks, or click blank then click option'
Amajority
Blinearizable
Cavailable
Dlocal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' which reads from the primary only and may not be fully consistent.
Using 'available' which is weaker consistency.
2fill in blank
medium

Complete the code to set the write concern to acknowledge writes by 3 nodes.

MongoDB
db.collection.insertOne(doc, { writeConcern: { w: [1] } })
Drag options to blanks, or click blank then click option'
A1
Bmajority
C3
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using w: 1 which only waits for primary acknowledgment.
Using w: 0 which does not wait for any acknowledgment.
3fill in blank
hard

Fix the error in the code to set read preference to nearest for better performance.

MongoDB
db.collection.find().readPreference('[1]')
Drag options to blanks, or click blank then click option'
AprimaryPreferred
Bprimary
CsecondaryPreferred
Dnearest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'primary' which always reads from the primary node, possibly slower.
Using 'secondaryPreferred' which prefers secondary but falls back to primary.
4fill in blank
hard

Fill both blanks to set a transaction with read concern 'snapshot' and write concern 'majority'.

MongoDB
session.startTransaction({ readConcern: { level: '[1]' }, writeConcern: { w: '[2]' } })
Drag options to blanks, or click blank then click option'
Asnapshot
Blocal
Cmajority
Dlinearizable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' read concern which is weaker for transactions.
Using write concern less than 'majority' which risks data loss.
5fill in blank
hard

Fill both blanks to create a read operation with read preference 'secondary', read concern 'local'.

MongoDB
db.collection.find().readPreference('[1]').readConcern('[2]')
Drag options to blanks, or click blank then click option'
Aprimary
Bsecondary
Clocal
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'primary' read preference which reads only from primary.
Using read concern 'majority' which provides stronger consistency but may impact performance.