{"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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cmap/connection_pool.ts#L193-L229","documentation":"Thrown in the ConnectionPool constructor (src/cmap/connection_pool.ts:210-214) when minPoolSize exceeds maxPoolSize. The pool enforces this invariant at construction because a minimum larger than the maximum is logically impossible and would leave the pool perpetually trying to grow. Maps to MongoInvalidArgumentError.","triggerScenarios":"Constructing MongoClient with { minPoolSize: N, maxPoolSize: M } where N > M, or the equivalent URI options (?minPoolSize=N&maxPoolSize=M). Fires immediately during MongoClient.connect() / first pool creation.","commonSituations":"Copy-pasting pool sizing from a sample where the values were swapped; setting minPoolSize to 'keep connections warm' but leaving maxPoolSize at a lower default; environment-specific config overrides that set min without adjusting max; misreading docs (minPoolSize default is 0, maxPoolSize default is 100).","solutions":["Ensure minPoolSize <= maxPoolSize; commonly set min to a fraction of max (e.g. min=10, max=100).","If you only want a floor, leave maxPoolSize at its default (100) and set only minPoolSize.","Audit environment-variable-driven config that injects these values independently.","Drop minPoolSize entirely if you do not need a warm pool - the default 0 is valid."],"exampleFix":"// before\nnew MongoClient(uri, { minPoolSize: 50, maxPoolSize: 20 });\n\n// after\nnew MongoClient(uri, { minPoolSize: 10, maxPoolSize: 50 });","handlingStrategy":"validation","validationCode":"function validatePoolSizes(min: number, max: number) {\n  if (min > max) {\n    throw new Error(`minPoolSize (${min}) must not exceed maxPoolSize (${max})`);\n  }\n  if (min < 0 || max < 0) throw new Error('pool sizes must be non-negative');\n}","typeGuard":"function areValidPoolSizes(min: unknown, max: unknown): boolean {\n  return typeof min === 'number' && typeof max === 'number' &&\n    min >= 0 && max >= 0 && min <= max;\n}","tryCatchPattern":"import { MongoInvalidArgumentError } from 'mongodb';\ntry {\n  const c = new MongoClient(uri, { minPoolSize, maxPoolSize });\n  await c.connect();\n} catch (e) {\n  if (e instanceof MongoInvalidArgumentError && /pool/i.test(e.message)) {\n    // swap or drop the offending value and recreate\n  }\n  throw e;\n}","preventionTips":["Default minPoolSize to 0 unless you need a warm pool.","Keep maxPoolSize >= minPoolSize; set them together in one config block.","Validate env-var-sourced pool sizes before constructing MongoClient."],"tags":["connection-pool","configuration","pool-sizing"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}