First Stop the mongod service, before setting the replica set
service mongodb stop
mongod --port "PORT" --dbpath "YOUR_DB_DATA_PATH" --replSet "REPLICA_SET_INSTANCE_NAME"
mongod --port 27017 --dbpath "D:\set up\mongodb\data" --replSet rs0 --fork
It will start a mongod instance with the name rs0, on port 27017. Now start the command prompt and connect to this mongod instance.
In mongo client issue the command rs.initiate() to initiate a new replica set.
rs.initiate()
To check the replica set configuration issue the command rs.conf().
rs.conf() should have the following
{
"_id" : "rs0"
"version" : 1,
"members" : [
{
"_id" : 0,
"host" "localhost:27017"
},
{
"_id" : 1,
"host" "localhost:27018"
},
{
"_id" : 2,
"host" "localhost:27019"
}
]
}
Now, you can add the additional nodes to the replication set by referencing the hostname you gave them.
rs.add("localhost:27019")
{ "ok" : 1 }
Do this for each of your remaining replication members. Your replication set should now be up and running.
To check the status of replica set issue the command rs.status().
rs.status()
Hope this helps.