8

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.

1

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Have you used it successfully with mongodb?
yes, of course, but this is generic pool module, you can use it literally with any resource
This should not be necessary. MongoDB native driver already does connection pooling internally.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.