Answer Posted / Asmita Shri
To start a replica set in MongoDB, you need to configure the members of the set and then initiate it. Here's an example for three members:
1. Create the replica set configuration file (replset.conf) with the following content:
```
rs.initiate({
_id : 'myReplSet',
members: [
{_id: 0, host : 'localhost:27017'},
{_id: 1, host : 'localhost:27018'},
{_id: 2, host : 'localhost:27019'}
]
})
```
2. Start MongoDB with the configuration file:
```
mongod --replSet myReplSet --smallfiles --config replset.conf
```
3. Repeat step 2 for each member of the replica set.
4. Connect to any of the members and check the status of the replica set:
```javascript
rs.status()
```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers