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

316
Visualizações
How to automatically reconnect to mongodb after connection loss?

I am trying to figure out how I can make my nodejs/express app to automatically reconnect to mongodb after a connection loss. I've noticed that my app loses the connection when I pause/stop my mongodb cluster and never recconnect even when I enable back the cluster. Therefore I need to manually restart my app in order to re-connect to mongodb. It's not ideal for a production environment.

After some researches, I've tried to setup my connection like this :

const options = {
            useNewUrlParser: true,
            useCreateIndex: true,
            useUnifiedTopology: true,
            useFindAndModify: false,
            autoIndex: true,
            autoReconnect:true,
            reconnectTries: Number.MAX_VALUE,
            reconnectInterval: 500,
            bufferMaxEntries: 0,
            connectTimeoutMS: 10000,
            socketTimeoutMS: 45000,
        }

  mongoose.connect(MONGO_URI, options);

But I get the following errors :

(node:21749) DeprecationWarning: The option `autoReconnect` is incompatible with the unified topology, please read more by visiting http://bit. ly/2D8WfT6
...
(node:21749) DeprecationWarning: The option `reconnectTries` is incompatible with the unified topology, please read more by visiting http://bit. ly/2D8WfT6
...
(node:21749) DeprecationWarning: The option `reconnectInterval` is incompatible with the unified topology, please read more by visiting http://bit. ly/2D8WfT6

Any suggestion ?

over 4 years ago · Santiago Trujillo
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