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

312
Views
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
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!