Replication is a vital feature in MongoDB for ensuring high availability and data redundancy. By leveraging replica sets, automatic failover, and flexible read and write configurations, MongoDB ensures robust performance under various scenarios. Test your understanding with these thoughtfully crafted multiple-choice questions (MCQs) covering all key aspects of replication.
Multiple-Choice Questions (MCQs)
1. Understanding Replica Sets
What is a MongoDB replica set? a) A group of collections with the same schema b) A set of databases in different servers c) A group of MongoDB instances with data replication d) A backup of MongoDB collections
How many nodes are recommended in a production replica set for fault tolerance? a) 1 b) 2 c) 3 d) 5
The primary node in a replica set: a) Serves as a backup only b) Handles all read and write operations c) Synchronizes data from the secondary node d) Is optional for the replica set
A secondary node in a replica set: a) Accepts write operations directly b) Stores only indexes c) Copies data from the primary node d) Controls election processes
What is an arbiter node in MongoDB? a) A node that stores data b) A node that participates in elections but does not store data c) A node used for backups d) A node dedicated to analytics
Which command is used to initiate a replica set in MongoDB? a) rs.initialize() b) rs.init() c) rs.start() d) rs.initiate()
2. Automatic Failover and Elections
What happens during a replica set election? a) A new primary is selected b) The replica set shuts down temporarily c) Data is deleted on secondary nodes d) Indexes are rebuilt on all nodes
What is the default priority for election of a primary node? a) 1 b) 0 c) -1 d) 5
How does an arbiter node help in a replica set? a) By storing backups of primary data b) By participating in elections to maintain quorum c) By balancing the read/write load d) By optimizing query performance
What happens if the primary node in a replica set fails? a) All operations stop until the primary is restored b) A secondary node is automatically promoted to primary c) The replica set goes into read-only mode d) An arbiter node takes over primary responsibilities
Which parameter defines the time interval for MongoDB’s replica set heartbeat checks? a) electionTimeoutMillis b) heartbeatFrequencyMS c) replicaTimeout d) primaryCheckInterval
Failover time in MongoDB replica sets depends on: a) Data size b) Number of nodes c) Election timeout settings d) Network latency
3. Read Preferences and Write Concerns
The default read preference in a MongoDB replica set is: a) secondary b) nearest c) primary d) any
Which read preference routes queries to the nearest node? a) primaryPreferred b) secondary c) nearest d) secondaryPreferred
What does writeConcern: {w: "majority"} mean? a) Write operations will wait for all nodes to acknowledge b) Write operations will wait for the majority of nodes to acknowledge c) Write operations occur only on the primary node d) Writes are performed asynchronously
The j: true option in write concern ensures: a) Faster writes b) Writes are acknowledged after being written to the journal c) Writes are performed on secondary nodes first d) Writes are distributed among all nodes
Which read preference minimizes data latency but may lead to stale reads? a) primary b) nearest c) secondary d) primaryPreferred
What is the purpose of wtimeout in write concerns? a) Limit the query execution time b) Set a time limit for write acknowledgment c) Control the number of nodes for write operations d) Define timeouts for read preferences
4. Replication Use Cases
Which of the following is a primary advantage of replication? a) Faster backups b) High availability c) Reduced storage requirements d) Improved schema design
In a geographically distributed replica set, the best read preference is: a) primaryPreferred b) nearest c) secondaryPreferred d) primary
Replication can be used for: a) Improving indexing performance b) Scaling writes across multiple nodes c) Disaster recovery and failover d) Schema migrations
MongoDB replication is not suitable for: a) Fault tolerance b) Data archival c) Load balancing writes d) Disaster recovery
A use case where MongoDB’s secondary read preference is ideal: a) Real-time analytics b) Reporting and background queries c) High-frequency writes d) Transactional workloads
Which replication use case benefits from writeConcern: {w: 1}? a) Critical systems requiring durability b) High-performance applications tolerating potential data loss c) Long-running analytics queries d) Distributed event processing
What is a major drawback of replication in MongoDB? a) Increased latency b) Additional storage overhead c) Lack of read scalability d) Complexity in query design
Answer Key
Qno
Answer (Option with Text)
1
c) A group of MongoDB instances with data replication
2
c) 3
3
b) Handles all read and write operations
4
c) Copies data from the primary node
5
b) A node that participates in elections but does not store data
6
d) rs.initiate()
7
a) A new primary is selected
8
a) 1
9
b) By participating in elections to maintain quorum
10
b) A secondary node is automatically promoted to primary
11
b) heartbeatFrequencyMS
12
c) Election timeout settings
13
c) primary
14
c) nearest
15
b) Write operations will wait for the majority of nodes to acknowledge
16
b) Writes are acknowledged after being written to the journal
17
b) nearest
18
b) Set a time limit for write acknowledgment
19
b) High availability
20
b) nearest
21
c) Disaster recovery and failover
22
c) Load balancing writes
23
b) Reporting and background queries
24
b) High-performance applications tolerating potential data loss