javascript - Should i close the Mongo connection after some operation? -


i understand best practice dealing database operations.

i use mongoose package, change mongodb package, cause don't need much, , know if should end connection after operation or leave open??

also, i'm using redis queue node-resque , have same doubt. i'm leaving both open, never close, doing wrong?

also, extending express instance - app - queue operation, can use in anywhere, wrong too?

thanks.

mongodb

it best practice open connection on application initialization , either have mongodb driver of choice manage connection pool (as drivers do, including js driver) or derive new connections "master" connection (as practice in go driver).

the reason why makes sense have driver manage connection pool simple: when number of connections left in pool drops below threshold, relative expensive operation of creating new socket connection mongodb , maybe authenticating done in background. when new connections requested application, not need created.

redis

i don't know redis, pub-sub scenario, should maintain connection updates asap.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -