How to increase MongoDB connection pool size?

I’m trying to incease mongodb connection pool size.

There isn’t much docs for this. But in mongodb docs I found poolSize parameter. But I couldn’t find how to implement this to parse server.

Then I found a github issue.

There is an example code:

config.databaseOptions = {
socketTimeoutMS: 60000
};
var api = new ParseServer(config);

I will change socketTimeoutMS to poolSize and add to my parse server.

But problem here is; I’m using parse-server-example repo. And I initialize my parse server like this:

var api = new ParseServer({
  allowClientClassCreation:false,
  databaseURI: databaseUri ,
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID,
  masterKey: process.env.MASTER_KEY 
});

And I dont know where to put config file in example code.

Can you guys help me please?

Edit: I found something.

databaseOptions: { poolSize: 500 },

I will add this directly to my parse server config like this:

var api = new ParseServer({
  allowClientClassCreation:false,
  databaseURI: databaseUri ,
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID,
  //Database Options
  databaseOptions: { poolSize: 500 },

  masterKey: process.env.MASTER_KEY 
});

Is this setup correct?

The configuration is correct regarding setting the poolSize. However, keep in mind that the DB connection string may also influence the pool size. The databaseOptions are directly passed to the MongoDB driver during initialization. Any option that is not set pre-request but globally during driver initialization can be set there. In addition, the Parse Server MongoDB Storage Adapter allows to set some custom parameters in the databaseOptions such as maxTimeMS, which are set pre-request.

1 Like

How? I didn’t understand this part well. Can you explain a little bit?

Some parameters that are set via the driver configuration can also be set via the connection string to the DB. In case you set the pool size via the connection string and via the driver configuration, I think the connection string takes precedence.

1 Like

Connection string is database uri. Right?

Like this: mongodb://username:pass@server/database

I don’t set any parameter with connection string.