---
title: Add a member to an existing MongoDB replica set
description: This topic discusses the steps to add a new node to an existing MongoDB replica set.
component: pingintelligence
version: 5.1
page_id: pingintelligence:abs_ai_engine:pingintelligence_add_member_to_existing_mongodb
canonical_url: https://docs.pingidentity.com/pingintelligence/5.1/abs_ai_engine/pingintelligence_add_member_to_existing_mongodb.html
revdate: April 3, 2024
section_ids:
  related-links: Related links
---

# Add a member to an existing MongoDB replica set

This topic discusses the steps to add a new node to an existing MongoDB replica set.

**Prerequisites:**

* An active replica set.

* A new MongoDB system accessible by the replica set.

* To add a new member, the MongoDB user must have`clusterAdmin` privileges.

|   |                                                                                            |
| - | ------------------------------------------------------------------------------------------ |
|   | ```
[.parmname]``absrs01`` is the name of the replica set used in the following steps.
``` |

Complete the following steps to add a node to an existing replica set:

1. Create the MongoDB directory structure: create mongo, data, logs, and key directory on the new MongoDB node.

   ```
   # mkdir -p /opt/pingidentity/mongo/data /opt/pingidentity/mongo/logs \ /opt/pingidentity/mongo/key
   ```

2. Download MongoDB 4.2 on the node and extract to `/opt/pingidentity/mongo`.

   ```
   # cd /opt/pingidentity/ /opt/pingidentity# wget \ https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.0.tgz \ -O mongodb.tgz && tar xzf mongodb.tgz -C /opt/pingidentity/mongo/ --strip-components=1
   ```

3. Update shell path variable and reload the shell.

   ```
   /opt/pingidentity# echo PATH=$PATH:/opt/pingidentity/mongo/bin >> ~/.bashrc; /opt/pingidentity# source ~/.bashrc
   ```

4. Copy the contents of the `/opt/pingidentity/mongo/key` directory from the primary node to the new node into `/opt/pingidentity/mongo/key`.

5. Start the MongoDB database on the new node.

   ```
   /opt/pingidentity# cd mongo /opt/pingidentity/mongo# mongod --auth --dbpath ./data/ --logpath ./logs/mongo.log --port 27017 --replSet absrs01 --fork --keyFile ./key/mongodb-keyfile -bind_ip 0.0.0.0
   ```

6. Connect to the mongo shell of the primary node and run the following command.

   ```
   absrs01:PRIMARY> rs.add({"host": "<IP address of new node>:27017", "priority": 2})
   ```

   |   |                                                                                                                                                                         |
   | - | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
   |   | On executing step-six, the state of the new node will change to STARTUP2. This indicates that the synchronization between the replica set and the new node has started. |

7. Verify if the new node is added as a Secondary node to the replica set using the following command.

   ```
   absrs01:PRIMARY> rs.status()
   ```

## Related links

* <https://docs.mongodb.com/manual/tutorial/expand-replica-set/>
