{"record":{"id":"094dff75db8bae0e","repo":"mongodb/node-mongodb-native","slug":"connection-pool-minimum-size-must-not-be-greater-t","errorCode":null,"errorMessage":"Connection pool minimum size must not be greater than maximum pool size","messagePattern":"Connection pool minimum size must not be greater than maximum pool size","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/cmap/connection_pool.ts","lineNumber":211,"sourceCode":"\n  constructor(server: Server, options: ConnectionPoolOptions) {\n    super();\n    this.on('error', noop);\n\n    this.options = Object.freeze({\n      connectionType: Connection,\n      ...options,\n      maxPoolSize: options.maxPoolSize ?? 100,\n      minPoolSize: options.minPoolSize ?? 0,\n      maxConnecting: options.maxConnecting ?? 2,\n      maxIdleTimeMS: options.maxIdleTimeMS ?? 0,\n      waitQueueTimeoutMS: options.waitQueueTimeoutMS ?? 0,\n      minPoolSizeCheckFrequencyMS: options.minPoolSizeCheckFrequencyMS ?? 100,\n      autoEncrypter: options.autoEncrypter\n    });\n\n    if (this.options.minPoolSize > this.options.maxPoolSize) {\n      throw new MongoInvalidArgumentError(\n        'Connection pool minimum size must not be greater than maximum pool size'\n      );\n    }\n\n    this.poolState = PoolState.paused;\n    this.server = server;\n    this.connections = new List();\n    this.pending = 0;\n    this.checkedOut = new Set();\n    this.minPoolSizeTimer = undefined;\n    this.generation = 0;\n    this.serviceGenerations = new Map();\n    this.connectionCounter = makeCounter(1);\n    this.cancellationToken = new CancellationToken();\n    this.cancellationToken.setMaxListeners(Infinity);\n    this.waitQueue = new List();\n    this.metrics = new ConnectionPoolMetrics();\n    this.processingWaitQueue = false;","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/connection_pool.ts#L193-L229","documentation":"A MongoInvalidArgumentError thrown in the ConnectionPool constructor when minPoolSize exceeds maxPoolSize. The pool enforces this invariant immediately at construction so an invalid configuration never reaches runtime. The defaults are minPoolSize=0 and maxPoolSize=100, so this only triggers when both are explicitly misconfigured.","triggerScenarios":"Constructing a MongoClient with minPoolSize greater than maxPoolSize in the connection string or options (e.g., ?minPoolSize=50&maxPoolSize=10).","commonSituations":"Copy-paste errors in connection string; tuning pool sizes for load and inverting the values; setting maxPoolSize low for a serverless/function environment while keeping a high minPoolSize from a previous config.","solutions":["Ensure minPoolSize <= maxPoolSize in the connection string and/or options.","Set maxPoolSize to at least the expected concurrent operation count.","Use minPoolSize=0 for serverless/short-lived environments.","Validate pool options at application startup with a config schema."],"exampleFix":"// before\nconst client = new MongoClient(uri + '?minPoolSize=50&maxPoolSize=10');\n\n// after\nconst client = new MongoClient(uri + '?minPoolSize=10&maxPoolSize=50');","handlingStrategy":"validation","validationCode":"const minPoolSize = 10;\nconst maxPoolSize = 50;\nif (minPoolSize > maxPoolSize) {\n  throw new Error('minPoolSize must be <= maxPoolSize');\n}\nconst client = new MongoClient(uri, { minPoolSize, maxPoolSize });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate pool options in a config schema at startup.","Use minPoolSize=0 for serverless/short-lived environments.","Keep maxPoolSize >= expected peak concurrency."],"tags":["config","connection-pool","validation","startup"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}