1

Im trying to initialize my replica set sp that the primary node has a specific domain:port pairing. what I want is:

"vagrant-ubuntu-trusty-64:27022"

but what I get is:

"localhost:27022"

This is the command I use to start the mongo instance:

sudo mongod --port 27022 --dbpath /db/config/data --configsvr --replSet config

This is what I use to access the mongo instance:

mongo --port 27022

I tried to modify my host file to add the domain name to the default domain of 127.0.0.1, but that didn't work.

127.0.0.1 localhost
127.0.0.1 vagrant-ubuntu-trusty-64
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

How do I get the specific "vagrant-ubuntu-trusty-64:27022" pairing when I initialize the mongo instance?

1 Answer 1

0

To add replica set members with hostname, pass the host name when initializing the replica set.

rs.initiate(
    {
        _id: "config",
        version: 1,
        members: [
        {_id: 0, host: "vagrant-ubuntu-trusty-64:27022"}
        ]
    }
)

_id --> is your replica set name

Or if you want to edit the existing configuration follow the below steps

var conf = rs.conf()

conf.members[0].host="vagrant-ubuntu-trusty-64:27022"

rs.reconfig(conf)

If you have more than one member in your replica set, all members should refer a hostname. Which means all members should be localhost or all members should be hostnames

4
  • it still gives me localhost:27022
    – tom dinh
    Commented Mar 8, 2019 at 20:58
  • Are you saying, you are localhost after connecting to the database in mongo shell?
    – Mani
    Commented Mar 8, 2019 at 20:59
  • once I initialize the mongodbi instance and access it, I do rs.initailize() and what I get is "me":"localhost:27022", but I want "me":"vagrant-ubuntu-trusty-64:27022"
    – tom dinh
    Commented Mar 8, 2019 at 21:02
  • As I mentioned in my answer, x.x.x.x is the IP address of your VM.
    – Mani
    Commented Mar 8, 2019 at 21:09

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.