Automattic/mongoose · error · Error

Limit must be positive

Error message

Limit must be positive

What it means

Error "Limit must be positive" thrown in Automattic/mongoose.

Source

Thrown at lib/helpers/parallelLimit.js:13

'use strict';

module.exports = parallelLimit;

/*!
 * Run `fn` over every entry of `params` with at most `limit` calls in flight at
 * a time, resolving to the results in input order. Currently only used by
 * `Model.insertMany()` to bound how many documents validate concurrently.
 */

async function parallelLimit(params, fn, limit) {
  if (limit <= 0) {
    throw new Error('Limit must be positive');
  }

  const length = params.length;
  if (length === 0) {
    return [];
  }

  const results = new Array(length);
  // Fast path: there's nothing to bound, so kick everything off and wait once.
  // Avoids the per-task `Set` + `Promise.race` bookkeeping of a sliding window.
  if (limit >= length) {
    for (let i = 0; i < length; ++i) {
      results[i] = fn(params[i], i);
    }
    return Promise.all(results);
  }

  let nextIndex = 0;

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/helpers/parallelLimit.js:13 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21). Data as JSON: /api/errors/c7c192fb48f46f0f. Report an issue: GitHub.