Automattic/mongoose · error · MongooseError
removeIndex() may only take either an object or a string as
Error message
removeIndex() may only take either an object or a string as an argument
What it means
Error "removeIndex() may only take either an object or a string as an argument" thrown in Automattic/mongoose.
Source
Thrown at lib/schema.js:1124
* 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);
}
}
}
return this;
};View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/schema.js:1124 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/1e7be906f12ecdf9.
Report an issue: GitHub.