0
0
MongoDBquery~20 mins

Write concern basics in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Write Concern Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the effect of write concern { w: 0 }?

Consider a MongoDB insert operation with the write concern set to { w: 0 }. What will be the behavior of this operation?

AThe operation returns immediately without waiting for any acknowledgment from the server.
BThe operation waits for acknowledgment from the primary only.
CThe operation waits for acknowledgment from all replica set members.
DThe operation fails immediately with an error.
Attempts:
2 left
💡 Hint

Think about what w: 0 means in terms of server acknowledgment.

query_result
intermediate
2:00remaining
What does write concern { w: 'majority' } guarantee?

In MongoDB, if you set the write concern to { w: 'majority' }, what does this guarantee about the write operation?

AThe write is acknowledged after being written to all members, including arbiters.
BThe write is acknowledged only by the primary node.
CThe write is acknowledged immediately without waiting.
DThe write is acknowledged after being written to a majority of voting replica set members.
Attempts:
2 left
💡 Hint

Consider what 'majority' means in a replica set context.

📝 Syntax
advanced
2:00remaining
Identify the invalid write concern option

Which of the following write concern options is invalid and will cause a syntax or runtime error in MongoDB?

A{ w: 2, wtimeout: 5000 }
B{ w: -1, j: false }
C{ w: 'majority', j: true }
D{ w: 1, wtimeout: 0 }
Attempts:
2 left
💡 Hint

Check the valid range and types for the w option.

🧠 Conceptual
advanced
2:00remaining
What happens if write concern timeout is reached?

If a write operation uses a write concern with a wtimeout set, and the timeout is reached before the write is acknowledged, what is the outcome?

AThe write operation waits indefinitely until acknowledged.
BThe write operation is aborted and rolled back automatically.
CThe write operation completes but the client receives a timeout error.
DThe write operation is acknowledged immediately ignoring the timeout.
Attempts:
2 left
💡 Hint

Think about what a timeout means for client acknowledgment.

🔧 Debug
expert
3:00remaining
Why does this write concern cause a write failure?

A MongoDB write operation uses the write concern { w: 3, wtimeout: 1000 } on a replica set with only 2 voting members. What error will occur and why?

AThe operation fails with a write concern error because the requested w is higher than the number of voting members.
BThe operation succeeds immediately because wtimeout is set to 1000 ms.
CThe operation fails with a syntax error due to invalid wtimeout value.
DThe operation ignores the write concern and writes only to the primary.
Attempts:
2 left
💡 Hint

Consider the relationship between w and the number of voting members in the replica set.