0
0
MongoDBquery~10 mins

Write concern and data durability 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 set the write concern to acknowledge writes on the primary only.

MongoDB
db.collection.insertOne({name: 'Alice'}, {writeConcern: {w: [1])
Drag options to blanks, or click blank then click option'
A1
B0
Cmajority
Dall
Attempts:
3 left
💡 Hint
Common Mistakes
Using w: 0 causes no acknowledgment and no guarantee of durability.
Using w: majority waits for multiple nodes, not just primary.
2fill in blank
medium

Complete the code to ensure the write is acknowledged by the majority of replica set members.

MongoDB
db.collection.insertOne({score: 100}, {writeConcern: {w: "[1]"}})
Drag options to blanks, or click blank then click option'
A0
B1
Cmajority
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using w: 1 only waits for primary, not majority.
Using w: 0 means no acknowledgment.
3fill in blank
hard

Fix the error in the write concern option to wait for journaling confirmation.

MongoDB
db.collection.insertOne({item: 'book'}, {writeConcern: {w: 1, j: [1])
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using j: false disables journaling acknowledgment, risking data loss.
Using j: 1 or 0 is invalid; it must be boolean true or false.
4fill in blank
hard

Fill both blanks to set write concern to wait for 2 nodes and enable journaling.

MongoDB
db.collection.insertOne({status: 'active'}, {writeConcern: {w: [1], j: [2])
Drag options to blanks, or click blank then click option'
A2
Btrue
Cfalse
Dmajority
Attempts:
3 left
💡 Hint
Common Mistakes
Using j as a number instead of boolean.
Using w as 'majority' when number 2 is required.
5fill in blank
hard

Fill all three blanks to set write concern with majority, journaling enabled, and a timeout of 5000 ms.

MongoDB
db.collection.insertOne({task: 'backup'}, {writeConcern: {w: "[1]", j: [2], wtimeout: [3])
Drag options to blanks, or click blank then click option'
A1
Btrue
C5000
Dmajority
Attempts:
3 left
💡 Hint
Common Mistakes
Using wtimeout as a boolean or string instead of a number.
Setting j to false disables journaling.