Mongodb – How to access mongodb replica set after restart

mongodbreplication

Yesterday I created a replica set and everything seemed to work. I closed all the cmd's when i was done.

I am assuming this replica set has not been deleted or anything, since old dbs i've created still are available. How can i access the replica set?

My replica set consists of three nodes on ports 27017, 27018 and 27019.
I have started

  • one mongod (the default one, for 27017)
  • mongo –port 27017
  • rs.status() which returns

    "ok" : 0,
    "errmsg" : "not running with --replSet",
    "code" : 76,
    "codeName" : "NoReplicationEnabled"
    

The node is most likely a secondary node, but it shouldn't matter. Even if I were to start the other two mongod's, i am feeling i'm missing something here.

I know this is probably a very stupid question. I am a beginner to mongo so please bear with me.

Best Answer

Check to see what processes you have running:

ps aux | grep mongod

You should see something like that:

mongod --port 27017 --replSet replica --dbpath s1 --logpath s1/monogd.log --fork
mongod --port 27018 --replSet replica --dbpath s2 --logpath s2/monogd.log --fork
mongod --port 27019 --replSet replica --dbpath s3 --logpath s3/monogd.log --fork

You will be able to connect using:

mongo "mongodb://localhost:27017, localhost:27018, localhost:27019/?replicaSet=replica"