{"record":{"id":"9e46185945df16ad","repo":"Automattic/mongoose","slug":"path-this-path-may-not-have-index-set-to-fa-9e4618","errorCode":null,"errorMessage":"Path \"${this.path}\" may not have `index` set to false and `text` set to true","messagePattern":"Path \"(.+?)\" may not have `index` set to false and `text` set to true","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/schemaType.js","lineNumber":592,"sourceCode":"/**\n * Declares a full text index.\n *\n * ### Example:\n *\n *      const s = new Schema({ name : { type: String, text : true } })\n *      s.path('name').index({ text : true });\n *\n * @param {boolean} bool\n * @return {SchemaType} this\n * @api public\n */\n\nSchemaType.prototype.text = function(bool) {\n  if (this._index === false) {\n    if (!bool) {\n      return this;\n    }\n    throw new MongooseError('Path \"' + this.path + '\" may not have `index` set to ' +\n      'false and `text` set to true');\n  }\n\n  if (!Object.hasOwn(this.options, 'index') && bool === false) {\n    return this;\n  }\n\n  if (this._index === null || this._index === undefined ||\n    typeof this._index === 'boolean') {\n    this._index = {};\n  } else if (typeof this._index === 'string') {\n    this._index = { type: this._index };\n  }\n\n  this._index.text = bool;\n  return this;\n};\n","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/schemaType.js#L574-L610","documentation":"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.","triggerScenarios":"`schema.path('name').index(false).text(true)`; `new Schema({ name: { type: String, index: false, text: true } })`.","commonSituations":"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.","solutions":["Remove `index: false` from the path before enabling text","Prefer a compound text index at the schema level: `schema.index({ title: 'text', body: 'text' })`","Use `autoIndex: false` to control index creation timing instead of per-path disabling"],"exampleFix":"// before\nnew Schema({ name: { type: String, index: false, text: true } }); // throws\n\n// after\nconst s = new Schema({ name: { type: String, text: true } });\n// or: s.index({ name: 'text' });","handlingStrategy":"validation","validationCode":"function configurePath(pathDef, opts) {\n  if (pathDef._index === false && opts.text === true) {\n    throw new Error('cannot enable text on a path with index:false; remove index:false first');\n  }\n  pathDef.text(opts.text);\n}","typeGuard":"const canEnableText = schematype => schematype._index !== false;","tryCatchPattern":null,"preventionTips":["Prefer schema-level compound text indexes (schema.index({a:'text', b:'text'})) over per-path text","Review any path that had index(false) before adding search features"],"tags":["mongoose","schema","index","text-search","options"],"backgroundTag":"invalid-schema-option","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}