2. Which of the following is the correct command to check the status of a MongoDB replica set?
easy
A. replica.status()
B. db.replicaStatus()
C. show replicaSet
D. rs.status()
Solution
Step 1: Recall MongoDB replica set commands
The command rs.status() is used to check the status of the replica set.
Step 2: Verify other options
Other options are not valid MongoDB shell commands for replica set status.
Final Answer:
rs.status() -> Option D
Quick Check:
Replica set status command = rs.status() [OK]
Hint: Use rs.status() to check replica set health [OK]
Common Mistakes:
Using incorrect or non-existent commands
Confusing database commands with replica set commands
Typing commands with wrong syntax
3. Given a replica set with one primary and two secondary nodes, what will happen if the primary node goes down?
medium
A. The replica set will stop all read and write operations immediately.
B. One of the secondary nodes will be elected as the new primary.
C. The primary node will automatically restart without intervention.
D. All secondary nodes will become primary nodes simultaneously.
Solution
Step 1: Understand replica set failover
If the primary node fails, the replica set automatically elects a new primary from the secondaries.
Step 2: Check other options
The replica set does not stop all operations; it does not restart primary automatically; multiple primaries cannot exist simultaneously.
Final Answer:
One of the secondary nodes will be elected as the new primary. -> Option B
Quick Check:
Failover elects new primary from secondaries [OK]
Hint: Replica sets auto-elect new primary if current fails [OK]
Common Mistakes:
Thinking all nodes become primary
Assuming system stops all operations
Believing primary restarts automatically
4. You run rs.stepDown() on the primary node but get an error saying "not primary". What is the likely cause?
medium
A. The node is already a secondary, not primary.
B. The command syntax is incorrect.
C. The replica set has only one node.
D. The network connection to the primary is lost.
Solution
Step 1: Understand rs.stepDown() usage
This command only works on a primary node to force it to step down.
Step 2: Analyze the error message
"not primary" means the node is already a secondary, so it cannot step down.
Final Answer:
The node is already a secondary, not primary. -> Option A
Quick Check:
rs.stepDown() error "not primary" = node is secondary [OK]
Hint: rs.stepDown() only works on primary nodes [OK]
Common Mistakes:
Trying to step down a secondary node
Assuming syntax error causes this message
Ignoring the node's current role
5. You want to configure a MongoDB replica set with one primary and two secondaries. Which of the following configurations ensures data safety and availability during a primary failure?
hard
A. Set all nodes with priority 1 and enable majority write concern.
B. Set one secondary with priority 0 and disable write concern.
C. Use only one node as primary without secondaries.
D. Set all nodes with priority 0 to prevent elections.
Solution
Step 1: Understand priority and write concern
Setting all nodes with priority 1 allows any secondary to become primary if needed. Majority write concern ensures writes are acknowledged by most nodes.
Step 2: Evaluate other options
Priority 0 disables election for that node; disabling write concern risks data loss; single node has no failover; priority 0 on all nodes prevents elections.
Final Answer:
Set all nodes with priority 1 and enable majority write concern. -> Option A