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

965
Visualizações
What is mean by +srv in mongoDb connection string

I am new to MongoDB and just encountered two types of connection string.

  1. mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]

  2. mongodb+srv://[username:password@]host[/[database][?options]]

I know about the 1st one. But unfamiliar with the (+srv) in the 2nd.

   let connectionUrl;
      if (username && password)
        connectionUrl = `mongodb://${username}:${password}@${host}:${
          port || 27017
        }/${databaseName}`;
      else
        connectionUrl = `mongodb://${host}:${
          port || 27017
        }/${databaseName}`;
      console.log(connectionUrl, "connectionUrlconnectionUrl");
      let connection = await mongoose.createConnection(connectionUrl, {
        useNewUrlParser: true,
      });
      return connection;

Now the problem user can enter username, password, hostname, etc...

But is there any way to know when to add (+srv) because I was trying with localhost and with MongoDB atlas. Atlas works fine with +srv but in the case of localhost, it's throwing an error.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

in MongoDB 3.6 is introduced the concept of a seed list that is specified using DNS records, specifically SRV and TXT records. You will recall from using replica sets with MongoDB that the client must specify at least one replica set member (and may specify several of them) when connecting. This allows a client to connect to a replica set even if one of the nodes that the client specifies is unavailable

You can see an example of this URL on a 2.2.12 or later connection string

enter image description here

Note that without the SRV record configuration we must list several nodes (in the case of Atlas we always include all the cluster members, though this is not required). We also have to specify the ssl and replicaSet options

With the 3.4 or earlier driver, we have to specify all the options on the command line using the MongoDB URI syntax.

The use of SRV records eliminates the requirement for every client to pass in a complete set of state information for the cluster. Instead, a single SRV record identifies all the nodes associated with the cluster (and their port numbers) and an associated TXT record defines the options for the URI.

enter image description here

check the Reference

over 4 years ago · Santiago Trujillo Relatório

0

In MongoDB 3.6, they introduced the concept of a seed list that is specified using DNS records, specifically SRV and TXT records.

This allows a client to connect to a replica set even if one of the nodes that the client specifies is unavailable.

over 4 years ago · Santiago Trujillo Relatório

0

If you wonder how to get the details yourself, assuming that your host would be foo.example.com

host -t SRV _mongodb._tcp.foo.example.com
host -t TXT foo.example.com
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