Automattic/mongoose · error · MongooseError

Schema#omit() only accepts an array argument, got "${typeof

Error message

Schema#omit() only accepts an array argument, got "${typeof paths}"

What it means

Error "Schema#omit() only accepts an array argument, got "${typeof paths}"" thrown in Automattic/mongoose.

Source

Thrown at lib/schema.js:579

 * #### Example:
 *
 *     const schema = Schema({ name: String, age: Number });
 *     // Creates a new schema omitting the `age` path
 *     const newSchema = schema.omit(['age']);
 *
 *     newSchema.path('name'); // SchemaString { ... }
 *     newSchema.path('age'); // undefined
 *
 * @param {string[]} paths List of Paths to omit for the new Schema
 * @param {object} [options] Options to pass to the new Schema Constructor (same as `new Schema(.., Options)`). Defaults to `this.options` if not set.
 * @return {Schema}
 * @api public
 */

Schema.prototype.omit = function(paths, options) {
  const newSchema = new Schema(this, options || this.options);
  if (!Array.isArray(paths)) {
    throw new MongooseError(
      'Schema#omit() only accepts an array argument, ' +
        'got "' +
        typeof paths +
        '"'
    );
  }

  newSchema.remove(paths);

  for (const nested in newSchema.singleNestedPaths) {
    if (paths.includes(nested)) {
      delete newSchema.singleNestedPaths[nested];
    }
  }

  return newSchema;
};

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/schema.js:579 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/e2d085697ac02ee0. Report an issue: GitHub.