Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
MongoDB replica set initiate

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?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

config = {id: "rs_name", members: [{id: 0, host: "127.0.0.1:27017"}]}

  1. replace id to _id

db.runCommand('replSetInitiate', config)

  1. use db.runCommand({replSetInitiate : config}) instead

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"?

  1. As mongodb docs described 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, the default configuration may use hostname instead of ip address.

FROM: https://docs.mongodb.com/manual/reference/command/replSetInitiate/

over 4 years ago · Santiago Trujillo Report

0

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)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!