0
0
MongoDBquery~10 mins

Why consistency levels matter in MongoDB - Test Your Understanding

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

Complete the code to read a document with strong consistency using MongoDB's read concern.

MongoDB
db.collection.findOne({}, {readConcern: {level: '[1]'}})
Drag options to blanks, or click blank then click option'
Amajority
Blocal
Cavailable
Dlinearizable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' which may read uncommitted data.
Choosing 'available' which is weaker consistency.
2fill in blank
medium

Complete the code to write a document with acknowledged write concern in MongoDB.

MongoDB
db.collection.insertOne({name: 'Alice'}, {writeConcern: {w: [1])
Drag options to blanks, or click blank then click option'
Amajority
Bunacknowledged
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using '0' which means no acknowledgment.
Using 'unacknowledged' which is not a valid w value.
3fill in blank
hard

Fix the error in the code to ensure a read uses linearizable consistency.

MongoDB
db.collection.find({}, {readConcern: {level: '[1]'}})
Drag options to blanks, or click blank then click option'
Alinearizable
Bmajority
Clocal
Davailable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'majority' which is strong but not linearizable.
Using 'local' which can read stale data.
4fill in blank
hard

Fill both blanks to set a write concern that waits for majority and a timeout of 5000ms.

MongoDB
db.collection.updateOne({name: 'Bob'}, {$set: {age: 30}}, {writeConcern: {w: '[1]', wtimeout: [2])
Drag options to blanks, or click blank then click option'
Amajority
B1000
C5000
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '1' instead of 'majority' for w.
Setting timeout too low or too high.
5fill in blank
hard

Fill all three blanks to create a read with majority level, a write with w=1, and a write timeout of 2000ms.

MongoDB
db.collection.find({}, {readConcern: {level: '[1]'}}); db.collection.insertOne({item: 'book'}, {writeConcern: {w: [2], wtimeout: [3])
Drag options to blanks, or click blank then click option'
Amajority
B1
C2000
Dlocal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' for read concern which is weaker.
Setting wtimeout too high or missing it.