0

I have started the mongodb server with replica set name 'rs01' enabled on port 27001.

Then started another command window to start the mongo db on the same port.

The status says the 'rs0' is not a member of the replica set.

rs0:OTHER> rs.status()
{
        "operationTime" : Timestamp(1552575009, 1),
        "ok" : 0,
        "errmsg" : "Our replica set config is invalid or we are not a member of it",
        "code" : 93,
        "codeName" : "InvalidReplicaSetConfig",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1552575009, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
}

But, if I try to register the member, below error message happens. Any help would be appreciated.

rs0:OTHER> rs.initiate({_id:"rs0",members[{_id:0,host:"localhost:27001"}]})
2019-03-14T22:14:39.840+0530 E QUERY    [js] SyntaxError: missing : after property id @(shell):1:30
rs0:OTHER> rsconf={ _id:"rs0", members: [ { _id: 0,host:"localhost:27001"}]}
{
        "_id" : "rs0",
        "members" : [
                {
                        "_id" : 0,
                        "host" : "localhost:27001"
                }
        ]
}
rs0:OTHER> rs.initiate(rsconf)
{
        "operationTime" : Timestamp(1552575009, 1),
        "ok" : 0,
        "errmsg" : "already initialized",
        "code" : 23,
        "codeName" : "AlreadyInitialized",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1552575009, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
}

mongodb

  • Please update your question with few more details like what is the command you used to start the mongod, and what command you used to connect to the mongod instance. – Mani Mar 15 at 16:35
  • @Nandy, What is the MongoDB version(x,y,z)? – Md Haidar Ali Khan Mar 17 at 3:59
0

As per error it seems like you have not configured properly the replica set. How to setup MongoDB Replica Set , you find here.

For example I am writing the steps here to setup MongoDB Replica Set

1) Start a mongod instance.

2) Start another mongod instance.

3) Start Replication.

After launcing the all mongod node instances, connect to any one node and start the mongo shell then type in command prompt

rs.initiate()

For example

Now the mongo shell prompt would be changed to yournodeinstancename:PRIMARY>

You may also check the status using rs.status() method.

rs.status()

for more info about rs.status() see the MongoDB documentation here and here

4) Add a MongoDB instance to the Replica Set.

rs.add();

5) Check the Status.

You may check the status of the Replica Set by running the following command

rs.status();

6) Getting an overview of the replica set and if current node is master

rs.isMaster()

For further your ref here , here , here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.