0
0
MongoDBquery~20 mins

Write concern levels (w: 1, majority) 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 does write concern w:1 guarantee?

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

AThe write is not acknowledged at all.
BThe write is acknowledged by all nodes in the replica set.
CThe write is acknowledged only after majority of nodes confirm.
DThe write is acknowledged by the primary node only.
Attempts:
2 left
💡 Hint

Think about which node confirms the write first in a replica set.

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 it guarantee about the write operation?

AThe write is acknowledged by a majority of voting nodes in the replica set.
BThe write is acknowledged by the primary node only.
CThe write is acknowledged by all nodes including arbiters.
DThe write is acknowledged only after all secondaries confirm.
Attempts:
2 left
💡 Hint

Majority means more than half of voting nodes.

📝 Syntax
advanced
2:00remaining
Which write concern syntax is correct to wait for majority?

Choose the correct MongoDB write concern syntax to ensure the write is acknowledged by the majority of replica set members.

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

Remember that 'majority' is a string value in write concern.

🧠 Conceptual
advanced
2:00remaining
Why might you choose write concern w:1 over w:'majority'?

Which reason best explains why a developer might choose { w: 1 } instead of { w: 'majority' } for write concern?

ATo guarantee writes are journaled on disk before acknowledgment.
BTo ensure data is written to all nodes before continuing.
CTo get faster write acknowledgments with less waiting.
DTo avoid any acknowledgment and improve performance.
Attempts:
2 left
💡 Hint

Think about speed versus durability trade-offs.

🔧 Debug
expert
2:00remaining
What error occurs with invalid write concern value?

Consider this MongoDB write operation with write concern:

{ w: 2 }

Assuming the replica set has only 3 nodes, what error or behavior will occur?

AThe write succeeds immediately without waiting for any nodes.
BThe write waits for acknowledgment from exactly 2 nodes and succeeds if they respond.
CThe write fails with <code>WriteConcernError</code> because w:2 is invalid for this replica set.
DThe write causes a syntax error and does not run.
Attempts:
2 left
💡 Hint

Write concern w can be a number specifying how many nodes must acknowledge.