Pooling in node-Mongodb-native when you need to call db.open and db.close

I have read most of the questions here about node-mongodb-native , but I cannot develop a standard practice regarding when I should open / close the connection.

Some sources talk about opening / closing as needed, some say they use a single instance of db. Does node-mongodb-native support auto pooling? If so, how to use it?

I would really like the code example showing the correct use of db.open and db.close in relation to, say, a login request.

+7
source share
2 answers

I suggest using a shared pool

This is very understandable and quite simple, you determine how to open the connection, how to close and the pool size. The module takes care of the rest, creating new connections as needed and deleting an unused connection after a timeout, which you also select.

I use the module with every resource that I need to pool, so I don’t have to worry about the custom pool API every time.

+4
source

This is the best answer I could find. It seems to work automatically, but I'm still figuring out the details.

Let me know if you find anything!

http://technosophos.com/node/255

+1
source

All Articles