简体   繁体   中英

To change the default connection in mongodb

Am working with node.js and mongodb and am quite new to the concepts, when tried to insert a huge data on to the mongodb the connection made with the mongodb on the local machine lost and the insertion stops and i found that the connection is made to insert the data to the db is 5 as it is the default connection, can please some one help me to increase the default connection from 5 or any suggestions to insert a huge data on to the mongodb using node.js. Am using mongoclient to establish the connection to the db.

The default pool size for connecting mongodb is 5 which is set as a default value. To increase the pool size use

var MongoClient = require('mongodb').MongoClient;
var mongoServer = require('mongodb').Server;
var serverOptions = {
    'auto_reconnect': true,
    'poolSize': 5
};
var mongoClient = new MongoClient(new mongoServer('localhost', 27017, serverOptions));

//Where in the pool size can be increased by increasing the poolSize value //eg: 'poolSize':100 will increase the connections into 100 provided the available connections are more.

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