Technology Encyclopedia Home >Does MongoDB support dynamic addition of secondary nodes?

Does MongoDB support dynamic addition of secondary nodes?

Yes, MongoDB supports the dynamic addition of secondary nodes. This is one of the key features of MongoDB's replica set architecture, which allows for horizontal scaling and high availability.

When you add a new secondary node to a replica set, MongoDB automatically synchronizes the data from the primary node to the new secondary. This process is called initial sync, and it ensures that the new node has a complete copy of the dataset. After the sync is complete, the secondary node starts receiving updates in real-time through the oplog (operation log).

Example:

Suppose you have a MongoDB replica set with one primary and two secondary nodes. If you need to scale out for read-heavy workloads, you can add a third secondary node dynamically:

  1. Start a new MongoDB instance with the same replica set configuration.
  2. Connect to the primary node and run the rs.add() command to include the new instance as a secondary:
    rs.add("new-secondary-host:27017")
    
  3. MongoDB will automatically initiate the initial sync process, and once completed, the new node will start serving read requests.

In Tencent Cloud, you can use TencentDB for MongoDB to easily manage replica sets and dynamically add secondary nodes through the console or API, ensuring seamless scalability and high availability.