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

768
Views
"MongoServerSelectionError: connection <monitor> to xxx.xx.xx.xxx:27017 closed

I am using AWS DocumentDB as my database in my application which is developed in node.js which is MongoDB compatible. I have used MongoClient to connect to my database. My application executes but it makes approx 1000 DB connections for each execution and then it fails with an error:

MongoServerSelectionError: connection <monitor> to xxx.xx.xx.xxx:27017 closed. 

I tried to use client.close() as well to close the connections then it gave that the connection pool is closed. I believe that issue is due to so many database connections.

How can I release the connections in MongoDB? Any help is appreciated.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It appears from your question that what is happening is that you are defining a new MongoClient object each time you invoke your function resulting in the driver creating a new database connection with each function call. Instead, define the client connection outside the AWS Lambda handler function and reuse the connection with each function call.

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!