Answer the question
In order to leave comments, you need to log in
Is a request pool necessary?
Hello. I am working with mongo-native-driver for Node.js. This is how I start working with the database:
const Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server;
const db = new Db('users', new Server('localhost', 27017));
db.open(function(err, connect) {
let users = connect.collection('users');
}
Answer the question
In order to leave comments, you need to log in
1) The connection pool actually means how many concurrent (simultaneous) requests to the database can be sent from a given node instance (in the script of which you describe the connection). But this number is not the only limitation, the mongo itself has a setting in the config, how many connections it can accept, plus not all requests can be processed at the same time (if they claim shared resources - https://docs.mongodb.com/manual/faq/ concurrency/ ). Plus, you can run several node instances in a cluster (then the pool size, in fact, will be multiplied by the number of node instances - https://nodejs.org/api/cluster.html). Therefore, it is not customary to rely on mongo parallelism, it is customary to architecture the application so that user requests do not require "powerful" operations from mongo ("powerful" operations are usually queued, immediately "letting go" of the client). The default value of 5 per node instance is fine for most cases.
2) If the application architecture allows - use the reference to the collection cached in the variable to execute queries. This will slightly (slightly) speed up accessing the collection by avoiding a few simple checks, and also potentially systematize the code a little.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question