I am quite new to MongoDB and have following question for replica set initiation.
When I tried to initiate a replica set from standalone mongod, I tried:
> use admin
> config = {id: "rs_name", members: [{id: 0, host: "127.0.0.1:27017"}]}
> db.runCommand('replSetInitiate', config)
"info2" : "no configuration specified. Using a default configuration for the set",
"ok": 1
...
Here is the first curiosity: Why did it show "no configuration" as I already assigned "config" as replica set configuration?
Though replica set was founded, when I tired:
> use local
> db.system.replset.find().pretty()
...
"members": [
{
"host": "here is hostname insted of host IP"
}
...
Here is the second ponit I didn't get: Why did the replica information show host name instead of host IP as value of property "host"?
But When I tried a different way:
> use admin
> config = {id: "rs_name", members: [{id: 0, host: "127.0.0.1:27017"}]}
> rs.initiate(config)
It went well and did not give any message like "no configuration specified". Replica information also showed host IP instead of host name.
Here is the last one: What is the difference between mechanism of replSetInitiate
and rs.initiate
when we try to initiate a replica set?
config = {id: "rs_name", members: [{id: 0, host: "127.0.0.1:27017"}]}
db.runCommand('replSetInitiate', config)
db.runCommand({replSetInitiate: config})
insteadHere is the second ponit I didn't get: Why did the replica information show host name instead of host IP as value of property "host"?
When possible, use a logical DNS hostname instead of an ip address, particularly when configuring replica set members or sharded cluster members.
. In the first step, you got no configuration specified. Using a default configuration for the set
no configuration specified. Using a default configuration for the set
, the default configuration may use hostname instead of ip address. FROM: https://docs.mongodb.com/manual/reference/command/replSetInitiate/
Please follow below and use _id which is highlighted below
use admin config = { _id : "rs_name", members: [ { _id : 0, host: "IP:27017"} ] }
rs.initiate(config)
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.