How to close and pass db connection in mongodb 3.6

27 views
Skip to first unread message

sanjay....@gmail.com

unread,
Mar 10, 2018, 9:47:14 PM3/10/18
to mongodb-user
Once I open the connection in the router function I can pass db object in request objects to next() function.


MongoClient.connect(client) { req.client=client; next(); }


Without closing the db connection I can pass it into next function and execute queries on the same db object.

The issue is I can't close idle connections that pile up I have tried using connectiontimeout, sockettimeout options but they wont work.


I don't want to open .connect and at the same time close it multiple times.


I want to open once use through out my application and close once.


Please help



Wan Bachtiar

unread,
Mar 27, 2018, 6:46:25 PM3/27/18
to mongodb-user

Hi Sanjay,

Could you provide more information about your environment: 

  • Which one of the MongoDB Drivers and version are you using ?
  • Are you utilising any other frameworks ?
  • Could you provide a snippet example on how you’re currently handling the connection ?

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages