Automattic/mongoose · error · MongooseError

Path "${this.path}" may not have `index` set to false and `t

Error message

Path "${this.path}" may not have `index` set to false and `text` set to true

What it means

SchemaType#text throws when passed a truthy value while the path's `_index` is already `false` (lib/schemaType.js:592). A text index is still an index, so `index: false` combined with `text: true` is contradictory and rejected before the schema can be used.

Source

Thrown at lib/schemaType.js:592

/**
 * Declares a full text index.
 *
 * ### Example:
 *
 *      const s = new Schema({ name : { type: String, text : true } })
 *      s.path('name').index({ text : true });
 *
 * @param {boolean} bool
 * @return {SchemaType} this
 * @api public
 */

SchemaType.prototype.text = function(bool) {
  if (this._index === false) {
    if (!bool) {
      return this;
    }
    throw new MongooseError('Path "' + this.path + '" may not have `index` set to ' +
      'false and `text` set to true');
  }

  if (!Object.hasOwn(this.options, 'index') && bool === false) {
    return this;
  }

  if (this._index === null || this._index === undefined ||
    typeof this._index === 'boolean') {
    this._index = {};
  } else if (typeof this._index === 'string') {
    this._index = { type: this._index };
  }

  this._index.text = bool;
  return this;
};

View on GitHub (pinned to 49cdab0136)

Solutions

  1. Remove `index: false` from the path before enabling text
  2. Prefer a compound text index at the schema level: `schema.index({ title: 'text', body: 'text' })`
  3. Use `autoIndex: false` to control index creation timing instead of per-path disabling

Example fix

// before
new Schema({ name: { type: String, index: false, text: true } }); // throws

// after
const s = new Schema({ name: { type: String, text: true } });
// or: s.index({ name: 'text' });
Defensive patterns

Strategy: validation

Validate before calling

function configurePath(pathDef, opts) {
  if (pathDef._index === false && opts.text === true) {
    throw new Error('cannot enable text on a path with index:false; remove index:false first');
  }
  pathDef.text(opts.text);
}

Type guard

const canEnableText = schematype => schematype._index !== false;

Prevention

When it happens

Trigger: `schema.path('name').index(false).text(true)`; `new Schema({ name: { type: String, index: false, text: true } })`.

Common situations: Adding full-text search to a path whose index was previously disabled; per-path `index: false` used as a blanket 'no indexes' policy clashing with text search requirements.

Related errors


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