MongoDB MCQs – Replication

MongoDB replication is a critical feature that ensures high availability and data redundancy. It involves maintaining multiple copies of data across different servers, known as replica sets. A replica set consists of a primary node (which handles all write operations) and secondary nodes (which replicate data from the primary). Replication helps in fault tolerance, load balancing, and disaster recovery.

This topic is frequently tested in interviews for roles involving database management and backend development. The following MCQs will help you prepare for such interviews by testing your knowledge of MongoDB replication concepts, configuration, and best practices.

1.) What is the primary purpose of replication in MongoDB?

A) To improve query performance
B) To encrypt data
C) To reduce storage costs
D) To ensure high availability and data redundancy

Answer: Option D

Explanation: Replication ensures high availability and data redundancy by maintaining multiple copies of data across different servers.

2.) What is a replica set in MongoDB?

A) A single MongoDB instance
B) A group of MongoDB instances that maintain the same data set
C) A backup of the database
D) A sharded cluster

Answer: Option B

Explanation: A replica set is a group of MongoDB instances that maintain the same data set for redundancy and high availability.

3.) How many nodes are required to form a replica set in MongoDB?

A) 1
B) 2
C) 3
D) 4

Answer: Option C

Explanation: A replica set requires at least three nodes to ensure proper election and fault tolerance.

4.) Which node in a replica set handles all write operations?

A) Primary node
B) Arbiter node
C) Secondary node
D) Hidden node

Answer: Option A

Explanation: The primary node is responsible for handling all write operations in a replica set.

5.) What is the role of an arbiter in a replica set?

A) To store data
B) To act as a backup node
C) To handle write operations
D) To participate in elections but not store data

Answer: Option D

Explanation: An arbiter participates in elections to break ties but does not store data.

6.) What happens if the primary node fails in a replica set?

A) The replica set stops working
B) A secondary node is elected as the new primary
C) Data is lost
D) The arbiter takes over as the primary

Answer: Option B

Explanation: If the primary node fails, an election occurs, and a secondary node is elected as the new primary.

7.) Which command is used to initiate a replica set in MongoDB?

A) rs.initiate()
B) rs.start()
C) rs.create()
D) rs.enable()

Answer: Option A

Explanation: The rs.initiate() command is used to initiate a replica set in MongoDB.

8.) What is the maximum number of voting members allowed in a replica set?

A) 7
B) 10
C) 50
D) 100

Answer: Option A

Explanation: A MongoDB replica set can have up to 50 members, but only 7 of them can be voting members. The remaining members can be non-voting members (e.g., delayed replicas, hidden members for analytics, or arbiters).

9.) Which of the following is true about secondary nodes?

A) They handle all write operations
B) They replicate data from the primary node
C) They do not participate in elections
D) They are read-only

Answer: Option B

Explanation: Secondary nodes replicate data from the primary node and can participate in elections.

10.) What is the purpose of the oplog in MongoDB replication?

A) To store encrypted data
B) To log all queries
C) To record all write operations for replication
D) To manage indexes

Answer: Option C

Explanation: The oplog (operations log) records all write operations to enable replication on secondary nodes.

Leave a Reply

Your email address will not be published. Required fields are marked *