5

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

2
  • 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, 2019 at 16:35
  • @Nandy, What is the MongoDB version(x,y,z)? Mar 17, 2019 at 3:59

3 Answers 3

5

In my situation (a local instance with a single node in the replica set). I ran rs.config() and saw that the members[0].host was incorrect.

I copy/pasted the config to an rs.reconfig command, edited the host id, and had to use {"force":true} as second argument.

I don't know if such a "brute" method will work for different settings.

rs.reconfig({ 
    "_id" : "rs0", 
    "version" : 1.0, 
    "protocolVersion" : NumberLong(1), 
    "writeConcernMajorityJournalDefault" : true, 
    "members" : [
        {
            "_id" : 0.0, 
            "host" : "2f0bd979cc69:27017", 
            "arbiterOnly" : false, 
            "buildIndexes" : true, 
            "hidden" : false, 
            "priority" : 1.0, 
            "tags" : {

            }, 
            "slaveDelay" : NumberLong(0), 
            "votes" : 1.0
        }
    ], 
    "settings" : {
        "chainingAllowed" : true, 
        "heartbeatIntervalMillis" : 2000.0, 
        "heartbeatTimeoutSecs" : 10.0, 
        "electionTimeoutMillis" : 10000.0, 
        "catchUpTimeoutMillis" : -1.0, 
        "catchUpTakeoverDelayMillis" : 30000.0, 
        "getLastErrorModes" : {

        }, 
        "getLastErrorDefaults" : {
            "w" : 1.0, 
            "wtimeout" : 0.0
        }, 
        "replicaSetId" : ObjectId("6033b612985ce53324d7446c")
    }
}, {"force":true})
3
  • You can edit the existing config by assigning it to a variable, as you can see here mongodb.com/docs/manual/tutorial/… but this works great. Thanks!
    – Simon
    May 9, 2022 at 11:24
  • I've just run into this issue myself with the exact same symptoms, in particular the hostname being changed to a "random" 6-byte hex string (MAC address?). Any idea what the root cause of this is, so I can prevent re-occurence?
    – Mac
    Jun 4, 2023 at 23:52
  • @Mac Sorry, I don't remember at this point. Jun 5, 2023 at 14:41
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

0

It could be all of you non-arbiter members were down, so there's no chance to restore the replica set.

In this case, you may need to force a member to be primary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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