How do I use a connection pool in nodejs?

59 views
Skip to first unread message

Everyharu

unread,
Jun 2, 2016, 5:30:22 AM6/2/16
to mongodb-user
How do I use a connection pool?

version : mongodb 3.0 version 
driver : mongodb-native



I try it.

var MongoClient = require('mongodb').MongoClient;
var db = null;
MongoClient.connect(sDbConnectUrl, {poolSize: 5}, function (err, mongodb) {
assert.equal(null, err);
db = mongodb;
if (err) {
throw err;
}
});


However, this does not hold.
In addition, the connection is not created five. Created only one.
And the connection can be disconnected if not used.

Kevin Adistambha

unread,
Jun 20, 2016, 1:20:22 AM6/20/16
to mongodb-user

Hi,

How do I use a connection pool?

version : mongodb 3.0 version
driver : mongodb-native

There is a sample code for connection pooling in the MongoClient connection pooling section of the MongoClient or how to connect in a new and better way page. As of this moment, the code snippet works using MongoDB node.js driver version 2.1.18

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages