mongodb/node-mongodb-native · error · MongoInvalidArgumentError
Connection pool minimum size must not be greater than…
Error message
Connection pool minimum size must not be greater than maximum pool size
What it means
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.
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.
Example fix
// before const client = new MongoClient(uri + '?minPoolSize=50&maxPoolSize=10'); // after const client = new MongoClient(uri + '?minPoolSize=10&maxPoolSize=50');
Defensive patterns
Strategy: validation
Validate before calling
const minPoolSize = 10;
const maxPoolSize = 50;
if (minPoolSize > maxPoolSize) {
throw new Error('minPoolSize must be <= maxPoolSize');
}
const client = new MongoClient(uri, { minPoolSize, maxPoolSize }); Prevention
- Validate pool options in a config schema at startup.
- Use minPoolSize=0 for serverless/short-lived environments.
- Keep maxPoolSize >= expected peak concurrency.
When it happens
Trigger: Constructing a MongoClient with minPoolSize greater than maxPoolSize in the connection string or options (e.g., ?minPoolSize=50&maxPoolSize=10).
Common situations: 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.
Related errors
- Unable to include driverInfo name and version, metadata…
- Unable to include driverInfo platform, metadata cannot…
- All values of tls/ssl must be the same.
- An operation cannot be given a timeoutMS setting when…
- Argument "docs" must be an array of documents
AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11).
Data as JSON: /api/errors/094dff75db8bae0e.
Report an issue: GitHub.
Appendix: source
Thrown at src/cmap/connection_pool.ts:211
constructor(server: Server, options: ConnectionPoolOptions) {
super();
this.on('error', noop);
this.options = Object.freeze({
connectionType: Connection,
...options,
maxPoolSize: options.maxPoolSize ?? 100,
minPoolSize: options.minPoolSize ?? 0,
maxConnecting: options.maxConnecting ?? 2,
maxIdleTimeMS: options.maxIdleTimeMS ?? 0,
waitQueueTimeoutMS: options.waitQueueTimeoutMS ?? 0,
minPoolSizeCheckFrequencyMS: options.minPoolSizeCheckFrequencyMS ?? 100,
autoEncrypter: options.autoEncrypter
});
if (this.options.minPoolSize > this.options.maxPoolSize) {
throw new MongoInvalidArgumentError(
'Connection pool minimum size must not be greater than maximum pool size'
);
}
this.poolState = PoolState.paused;
this.server = server;
this.connections = new List();
this.pending = 0;
this.checkedOut = new Set();
this.minPoolSizeTimer = undefined;
this.generation = 0;
this.serviceGenerations = new Map();
this.connectionCounter = makeCounter(1);
this.cancellationToken = new CancellationToken();
this.cancellationToken.setMaxListeners(Infinity);
this.waitQueue = new List();
this.metrics = new ConnectionPoolMetrics();
this.processingWaitQueue = false;View on GitHub (pinned to dce7939f86)