0
0
MongoDBquery~10 mins

Write concern levels (w: 1, majority) 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 write concern to acknowledge writes by the primary only.

MongoDB
db.collection.insertOne({name: "Alice"}, {writeConcern: {w: [1])
Drag options to blanks, or click blank then click option'
A0
Ball
Cmajority
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 means no acknowledgment.
Using 'majority' waits for more nodes.
2fill in blank
medium

Complete the code to set write concern to wait for majority of nodes to acknowledge.

MongoDB
db.collection.updateOne({_id: 1}, {$set: {score: 100}}, {writeConcern: {w: [1])
Drag options to blanks, or click blank then click option'
A1
B0
Cmajority
Dall
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 waits only for primary.
Using 0 means no acknowledgment.
3fill in blank
hard

Fix the error in the write concern option to correctly wait for majority acknowledgment.

MongoDB
db.collection.deleteOne({_id: 5}, {writeConcern: {w: [1])
Drag options to blanks, or click blank then click option'
Amajority
B1
CMajority
Dall
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized 'Majority' causes error.
Using numeric values won't wait for majority.
4fill in blank
hard

Fill both blanks to set write concern to acknowledge by primary and timeout after 5000ms.

MongoDB
db.collection.insertMany(docs, {writeConcern: {w: [1], wtimeout: [2])
Drag options to blanks, or click blank then click option'
A1
Bmajority
C5000
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'majority' with a low timeout may cause errors.
Using 0 for w means no acknowledgment.
5fill in blank
hard

Fill all three blanks to set write concern to majority, timeout 2000ms, and journal enabled.

MongoDB
db.collection.updateMany(filter, update, {writeConcern: {w: [1], wtimeout: [2], j: [3])
Drag options to blanks, or click blank then click option'
A1
B2000
CTrue
Dmajority
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'true' as string instead of boolean.
Using 0 for w disables acknowledgment.