Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

317
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda