Automattic/mongoose · error · MongooseError

removeIndex() takes only 1 argument

Error message

removeIndex() takes only 1 argument

What it means

Error "removeIndex() takes only 1 argument" thrown in Automattic/mongoose.

Source

Thrown at lib/schema.js:1120

 *     ToySchema.index({ name: 1, color: 1 });
 *
 *     // Remove index on { name, color }
 *     // Keep in mind that order matters! `removeIndex({ color: 1, name: 1 })` won't remove the index
 *     ToySchema.removeIndex({ name: 1, color: 1 });
 *
 *     // Add an index with a custom name
 *     ToySchema.index({ color: 1 }, { name: 'my custom index name' });
 *     // Remove index by name
 *     ToySchema.removeIndex('my custom index name');
 *
 * @param {object|string} index name or index specification
 * @return {Schema} the Schema instance
 * @api public
 */

Schema.prototype.removeIndex = function removeIndex(index) {
  if (arguments.length > 1) {
    throw new MongooseError('removeIndex() takes only 1 argument');
  }

  if (typeof index !== 'object' && typeof index !== 'string') {
    throw new MongooseError('removeIndex() may only take either an object or a string as an argument');
  }

  if (typeof index === 'object') {
    for (let i = this._indexes.length - 1; i >= 0; --i) {
      if (isIndexSpecEqual(this._indexes[i][0], index)) {
        this._indexes.splice(i, 1);
      }
    }
  } else {
    for (let i = this._indexes.length - 1; i >= 0; --i) {
      if (this._indexes[i][1] != null && this._indexes[i][1].name === index) {
        this._indexes.splice(i, 1);
      }
    }

View on GitHub (pinned to 49cdab0136)

When it happens

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