简体   繁体   中英

Mongodb Client connections with node.js issue

When I run my MongoDB connection with my node.js application which gaming platform here I facing the problem of an increasing number of MongoDB connections [Without using any query but its increasing repeatedly] which reaches to 819 and my MongoDB replication server stop responding and indirectly application stop the work. But I want to maintain a minimum of 20 connections on how to solve these issues please help me.

**

Mongodb connection: const connectionString = 'mongodb://AAAA:PASSWORD@HOST1:27001,HOST2:27002,HOST3:27003/dbName?replicaSet=rep1';

MongoClient.connect(connectionString, function (err, database) {
if (err) { console.log(err); console.log("unable to connect Mongodb database on url: " + connectionString);
} else { dbs['dashboardLog'] = database; console.log("Mongodb database connected to server on url: " + connectionString); } });

**

I am using MongoDB client driver version: 3.4.23 Node.js: version 6.11

Fade-up with this issue please helps thanks in advance!!!

MongoClient already comes with connection pool support, just set the value you want for poolSize , if I remember correctly the default is 5 so set it to 20. You don't have to create a new connection everytime you want to run a new query. Just connect once and then keep that around.

See this article for more information https://blog.mlab.com/2017/05/mongodb-connection-pooling-for-express-applications/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM