Reputation: 24406
When using the native mongo.db driver for node, should I open 1 connection per application, per page "serve", or open and close it whenever I need?
I've seen a few older answers but I know the project is always developing so I want to know what it the status today.
Upvotes: 1
Views: 633
Reputation: 65343
This isn't a situation that will change; opening a new connection to a server will be less performant than using an established connection.
Note: this is the general case for server applications, and not specific to MongoDB.
Typical overhead includes:
For MongoDB in particular:
For the MongoDB Node.js driver you can take advantage of connection pooling by setting the poolSize in the constructor. A blog post with an example of using this: Node.js: Connection Pools and MongoDB.
Upvotes: 2