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

604
Views
MongoDB failed to connect connection timed out: Connects via Atlas

When starting my app, I get the following error:

error: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkTimeoutError: connection timed out
    backend_1     |       at connectionFailureError (/usr/src/app/node_modules/mongodb/lib/core/connection/connect.js:342:14)
    backend_1     |       at Socket.<anonymous> (/usr/src/app/node_modules/mongodb/lib/core/connection/connect.js:310:16)
    backend_1     |       at Object.onceWrapper (events.js:421:28)
    backend_1     |       at Socket.emit (events.js:315:20)
    backend_1     |       at Socket._onTimeout (net.js:483:8)
    backend_1     |       at listOnTimeout (internal/timers.js:554:17)
    backend_1     |       at processTimers (internal/timers.js:497:7)]
    backend_1     |       at Pool.<anonymous> (/usr/src/app/node_modules/mongodb/lib/core/topologies/server.js:438:11)
    backend_1     |       at Pool.emit (events.js:315:20)
    backend_1     |       at /usr/src/app/node_modules/mongodb/lib/core/connection/pool.js:562:14
    backend_1     |       at /usr/src/app/node_modules/mongodb/lib/core/connection/pool.js:995:11
    backend_1     |       at /usr/src/app/node_modules/mongodb/lib/core/connection/connect.js:32:7
    backend_1     |       at callback (/usr/src/app/node_modules/mongodb/lib/core/connection/connect.js:280:5)
    backend_1     |       at Socket.<anonymous> (/usr/src/app/node_modules/mongodb/lib/core/connection/connect.js:310:7)
    backend_1     |       at Object.onceWrapper (events.js:421:28)
    backend_1     |       at Socket.emit (events.js:315:20)
    backend_1     |       at Socket._onTimeout (net.js:483:8)
    backend_1     |       at listOnTimeout (internal/timers.js:554:17)
    backend_1     |       at processTimers (internal/timers.js:497:7),


However, I can connect to the MongoDB service via MongoDBCompass and the Database connection tool in WebStorm, using the same connection string. "mongodb://localhost:27017/fmis"

I'm struggling to find the root cause to even try and solve it myself.

Update: as asked in the comments, I am running docker

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I solved this by including the following in my connection configuration:

mongoose.connect(
    db,
    {
        ...
        useUnifiedTopology: true   //THIS SETTING
    })
    ...
)
over 4 years ago · Santiago Trujillo Report
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!