We’re trying to get the MongoDB Node Driver to only use a single connection to avoid reaching our Atlas max concurrent connections limit.
However it seems the poolSize:1
& maxPoolSize: 1
options are plainly ignored by the driver.
To reproduce (Mongo Node Driver 3.6.8, Node.js 16.4.0, Atlas 3-node replica set running MongoDB 4.4.6):
- run in Node
mongodb = require('mongodb')
let MC = new mongodb.MongoClient('mongodb+srv://myreplicaset-vtcmd.mongodb.net/mydb', {
tls: true,
auth: {user: 'myuser', password:'mypassword'},
useNewUrlParser: true,
useUnifiedTopology: true,
poolSize: 1,
maxPoolSize: 1
})
- run in shell
$ lsof -i tcp:27017
node 8250 user 27u IPv4 0xe04adf2892fda27d 0t0 TCP 192.168.1.115:52663->ec2-52-47-xx-xx.eu-west-3.compute.amazonaws.com:27017 (ESTABLISHED)
node 8250 user 28u IPv4 0xe04adf2877cb427d 0t0 TCP 192.168.1.115:52668->ec2-15-236-xx-xx.eu-west-3.compute.amazonaws.com:27017 (ESTABLISHED)
node 8250 user 29u IPv4 0xe04adf289301f9dd 0t0 TCP 192.168.1.115:52662->ec2-15-188-xx-xx.eu-west-3.compute.amazonaws.com:27017 (ESTABLISHED)
node 8250 user 30u IPv4 0xe04adf287abf7b1d 0t0 TCP 192.168.1.115:52661->ec2-15-236-xx-xx.eu-west-3.compute.amazonaws.com:27017 (ESTABLISHED)
node 8250 user 31u IPv4 0xe04adf28933e627d 0t0 TCP 192.168.1.115:52669->ec2-15-188-xx-xx.eu-west-3.compute.amazonaws.com:27017 (ESTABLISHED)
node 8250 user 32u IPv4 0xe04adf287240058d 0t0 TCP 192.168.1.115:52670->ec2-52-47-xx-xx.eu-west-3.compute.amazonaws.com:27017 (ESTABLISHED)
Shouldn’t there be a single TCP connection here, or am I misunderstanding how poolSize
applies to Unified Topology replica sets ?