Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda