Monday, 15 May 2017

Should I use same MongoClient instance for multiple MongoDB connections?

We will have multiple MongoDB connection URIs in our NodeJS application. These connections are to different servers in different locations, some of which are replica-sets. In the current API docs, there are 2 different methods to open a connection. One involves creating a new instance of MongoClient and the other involves using the existing MongoClient instance static connect method. In the MongoDB tutorial, they re-use the MongoClient instance versus creating a new one.

Which would be more appropriate to use in my case? Should I create a new MongoClient() instance then call connect, or should I reuse the instance provided in the module on every connection?

Note: I am not talking about re-using the connection/database returned by connect, only the MongoClient instance itself.



via wayofthefuture

No comments:

Post a Comment