How to connect to replica set after restart

Hello,

I created a replica set the other day with the following ports:
Primary - 27017
Secondary - 27020
Secondary - 27030

It worked fine. I closed all command prompts and came back to it a few days later. Now, when I run mongod in one command window, and then try to run the Primary node of my replica set using:

mongo “mongodb://localhost:27017, localhost:27020, localhost:27030/?replSet=company1repl”

I get the following message:

"Document(s) exist in ‘system.replset’, but started without --replSet’.

I am specifying a replSet in the command, so why am I getting that message? And just how do I connect to my nodes in the replica set?

My apologies if this is a silly question, but I am new to this and have spent hours trying to figure out why I can’t access the replica set.

Any comments or suggestions are greatly appreciated. Thank you!

1 Like

I should have mentioned that I am trying to do everything through Windows cmd, as part of an exercise for my studies.
Also, I am using MongoDB v5.0.3.

It may be complaining about how you started mongod rather than how you connected
How did you start mongod when it was working before?
If you ran just mongod it will bring up default mongod (without replication)
You must have used config file which has replication params

Hi Ramachandra,

When started mongod and it ran, I used the following:

mongod --dbpath “C:\Program Files\MongoDB\Server\5.0\data” --logpath “C:\Program Files\MongoDB\Server\5.0\log\mongod.log” --port 27017 --storageEngine=wiredTiger --journal --replSet company1repl"

Then, once in the MongoDB Enterprise prompt, I entered:

"rsconf={_id:“company1repl”,members:[{_id:0,host:“localhost:27017”}]}

after which I did

rs.initiate(rsconf).

And that worked. But, if I’m not mistaken, isn’t that how you configure the replica set? I mean, am I supposed to type that each time I want to connect to the replica set? And after that add the secondary instances?

Thanks so much for your help.

These are the steps you followed for initial setup
How did you start mongod today?

I typed “mongod” in a separate cmd window.

Then, in another cmd window, I typed:

mongo “mongodb://localhost:27017, localhost:27020, localhost:27030/?replSet=company1repl”

Sorry, @Ramachandra_Tummala, to intervene but you usually have replied at this time since it looks like you are a few timezone ahead of me. I am sure your reply would like:

The following is wrong:

You must used the same argument as when you started mongod the first time. That is:

The following connection string is also wrong.

The option is replicaSet rather than replSet. See https://docs.mongodb.com/upcoming/reference/connection-string/#std-label-connections-connection-options.

4 Likes

Well thank you very much, Steve. I now enter the arguments like you mentioned, start up a mongod instance for each node, and than I can run the mongo “mongodb://localhost:27017,localhost:27020,localhost:27030/?replicaSet=company1repl” command and it works.

It was such a simple problem but I just couldn’t wrap my head around it. Thanks again for your time and help.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.