Error changing host name mongodb replicaset

I have a mongodb replicator on ubuntu. In the replica set, hosts are defined as localhost. You can see:

{ "_id" : "myrep", "version" : 4, "members" : [ { "_id" : 0, "host" : "localhost:27017" }, { "_id" : 2, "host" : "localhost:27018" }, { "_id" : 1, "host" : "localhost:27019", "priority" : 0 } ] 

}

I want to change the host address using a real ip server. But when I run rs.reconfig, I get an error:

 { "assertion" : "hosts cannot switch between localhost and hostname", "assertionCode" : 13645, "errmsg" : "db assertion failure", "ok" : 0 

}

How can i solve this? Thanks.

+6
source share
2 answers

The only way I can change the hostnames is to recreate the replica set. To make it correct, you need to clear the db directories. Then start all servers with replication mode after it created a new repset with new host names. / P>

+1
source

There is a cleaner way to do this:

 use local cfg = db.system.replset.findOne({_id:"replicaSetName"}) cfg.members[0].host="newHost:27017" db.system.replset.update({_id:"replicaSetName"},cfg) 

then restart mongo

+19
source

Source: https://habr.com/ru/post/900436/


All Articles