With MongoDB, a suggestion was to always re-use the same database connection, and have a pool of connections to support some concurrency.
In node-mongodb-native
1.x
you could configure the db and server object, creating a pool like so:
var server = new Server(
config.host,
config.port,
{
auto_reconnect : true,
poolSize : 5 // <= here is the pool
}
);
var db = new Db(
config.database,
server
);
db.open(function(err, db) {
// ...
}
In 2.0
they deprecated everything except MongoClient
for connecting:
MongoClient.connect(URI, callback);
Where do I add the pool options? Do I have a pool now automatically?
With 2.1
they go a step further and suggest using a generator: https://mongodb.github.io/node-mongodb-native/2.1/reference/ecmascript6/connecting/
Is this effectively using a separate connection for every action again? Is using pools obsolete?