Setting the connection pool size to 1 seems to still result in at-least 3 connections. This is problematic in autoscaled and "serverless" environments in which many small instances are created.
The following options on connect():
MongoClient.connect(url,{{{ }}
{{ poolSize:1 }}
}).then(client =>{{{ }}
{{ console.log("Success"); }}
{{ client.close(); }}
}).catch(err => console.error(err));
{{ }}
{{ Result in these logs being shown when debug logs are enabled:}}
{{ }}
{{ {{[DEBUG-Connection:98625] 1528928831926 creating connection 0 with options [
{"host":"dev-public-data-shard-00-00-axw3m.gcp.mongodb.net","port":27017,"size":1,"keepAlive":true,"keepAliveInitialDelay":300000,"noDelay":true,"connectionTimeout":30000,"socketTimeout":360000,"ssl":true,"ca":null,"crl":null,"cert":null,"rejectUnauthorized":false,"promoteLongs":true,"promoteValues":true,"promoteBuffers":false,"checkServerIdentity":true}
] { type: 'debug',}}}}
{{ {{ message: 'creating connection 0 with options [
{"host":"dev-public-data-shard-00-00-axw3m.gcp.mongodb.net","port":27017,"size":1,"keepAlive":true,"keepAliveInitialDelay":300000,"noDelay":true,"connectionTimeout":30000,"socketTimeout":360000,"ssl":true,"ca":null,"crl":null,"cert":null,"rejectUnauthorized":false,"promoteLongs":true,"promoteValues":true,"promoteBuffers":false,"checkServerIdentity":true}
]',}}}}
{{ {{ className: 'Connection',}}}}
{{ {{ pid: 98625,}}}}
{{ {
{ date: 1528928831926 }
}}}}
{{ {{[DEBUG-Connection:98625] 1528928831947 creating connection 1 with options [
{"host":"dev-public-data-shard-00-01-axw3m.gcp.mongodb.net","port":27017,"size":1,"keepAlive":true,"keepAliveInitialDelay":300000,"noDelay":true,"connectionTimeout":30000,"socketTimeout":360000,"ssl":true,"ca":null,"crl":null,"cert":null,"rejectUnauthorized":false,"promoteLongs":true,"promoteValues":true,"promoteBuffers":false,"checkServerIdentity":true}
] { type: 'debug',}}}}
{{ {{ message: 'creating connection 1 with options [
{"host":"dev-public-data-shard-00-01-axw3m.gcp.mongodb.net","port":27017,"size":1,"keepAlive":true,"keepAliveInitialDelay":300000,"noDelay":true,"connectionTimeout":30000,"socketTimeout":360000,"ssl":true,"ca":null,"crl":null,"cert":null,"rejectUnauthorized":false,"promoteLongs":true,"promoteValues":true,"promoteBuffers":false,"checkServerIdentity":true}
]',}}}}
{{ {{ className: 'Connection',}}}}
{{ {{ pid: 98625,}}}}
{{ {
{ date: 1528928831947 }
}}}}
{{ {{[DEBUG-Connection:98625] 1528928831950 creating connection 2 with options [
{"host":"dev-public-data-shard-00-02-axw3m.gcp.mongodb.net","port":27017,"size":1,"keepAlive":true,"keepAliveInitialDelay":300000,"noDelay":true,"connectionTimeout":30000,"socketTimeout":360000,"ssl":true,"ca":null,"crl":null,"cert":null,"rejectUnauthorized":false,"promoteLongs":true,"promoteValues":true,"promoteBuffers":false,"checkServerIdentity":true}
] { type: 'debug',}}}}
{{ {{ message: 'creating connection 2 with options [
{"host":"dev-public-data-shard-00-02-axw3m.gcp.mongodb.net","port":27017,"size":1,"keepAlive":true,"keepAliveInitialDelay":300000,"noDelay":true,"connectionTimeout":30000,"socketTimeout":360000,"ssl":true,"ca":null,"crl":null,"cert":null,"rejectUnauthorized":false,"promoteLongs":true,"promoteValues":true,"promoteBuffers":false,"checkServerIdentity":true}
]',}}}}
{{ {{ className: 'Connection',}}}}
{{ {{ pid: 98625,}}}}
{{ {
{ date: 1528928831950 }
}}}}
{{ }}
{{ This seems to suggest 3 connections are being created. Is this the case? And if so, is there a way to limit the actual connections to 1?}}