简体   繁体   中英

mongoDB set name does not match

I have got 3 mongod demo replicates servers running on my machine. I have used following command to create replicated server:

F:\>mongod --replSet test2 --dbpath 2 --port 27112 --oplogSize 50 --logpath log.2 --logappend
all output going to: log.2

Like this I have test1 on 27111 port, test2 on 27112 port and test3 on 27113 port. Yet at configuration I am getting an error:

cfg = {
        "_id" : "test1",
        "members" : [
                {
                        "_id" : 0,
                        "host" : "localhost:27111"
                },
                {
                        "_id" : 1,
                        "host" : "localhost:27112"
                },
                {
                        "_id" : 2,
                        "host" : "localhost:27113"
                }
        ]
}
> rs.initiate( cfg )
{
        "errmsg" : "couldn't initiate : set name does not match the set name host localhost:27112 expects",
        "ok" : 0
}

Now what do I have to do to make it match ?

All the sets I would run should have the same name. For an instance if I run

mongod --replSet test2 --dbpath 2 --port 27112 --oplogSize 50 --logpath log.2 --logappend
all output going to: log.2

Then the other mongo servers I would intend to be in that set, should have the same name test2

The name or variable used in "cfg" = { "_id":="test1" }

should confirm with the name used in the following for parameter replSet for all the members in that replication set.

Then things will work smoothly for you

"start mongod --replSet "test1" --logpath "1.log" --dbpath C:\Replica\rs01 --port 27017 --oplogSize 64

Good luck

Rao

Try with the name of your machine or 127.0.0.1. It's a best practice to use the DNS name.

MongoDB replicaset doesn't accept localhost . Try using the actual machine name while adding the node to the replicaset as following:

rs.add("MY_MACHINE_NAME:27017");

When adding the replica sets, the --replset should be same for all three. For example if for primary it was "rs01", it should be same for other two also .

The steps below worked for me:

mongod --port 27017 --dbpath "C:\MongoDB\data01" --replSet rs0 --bind_ip localhost
mongod --port 27018 --dbpath "C:\MongoDB\data02" --replSet rs0 --bind_ip localhost

These two lines start two different mongo instances in different ports. On the second instance, I have added replSet=rs0 in mongod.conf.

Then add the secondary in rs0 node by this command:

rs.add("localhost:27018")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM