I've read most questions here about node-mongodb-native but I can't work out the standard practice as to when I should open/close a connection.
Some sources say open/close as needed, some say use one db instance throughout. Does node-mongodb-native support automatic connection pooling? If so, how do I use this?
I would really appreciate example code showing correct use of db.open
and db.close
in relation to, say, a login request.
I suggest to use generic-pool
It's very clear and pretty straightforward, you define how to open connection, how to close, and size of the pool. The module takes care of the rest, creating new connections as needed, and disposing unused connection after timeout you also select.
I use the module with every resource I need to pool, so I dont have to bother with custom pooling API every time.
This is the best answer I could find. Apparently, it works automatically, but I'm still figuring out the details.
Let me know if you find anything!
http://technosophos.com/node/255
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With