Index is not getting created, text index required for $text query - mongoose Index is not getting created, text index required for $text query - mongoose mongoose mongoose

Index is not getting created, text index required for $text query - mongoose


Below line:

adSchema.index({ title: 'text', description: 'text', tags: 'text' })

correctly defines an index on mongoose schema (not on a database). By default mongoose creates indexes when your application starts up (link) however you're preventing it by using autoIndex: false.

So you have to either remove that line or run createIndexes on your model explicitly:

adSchema.index({ title: 'text', description: 'text', tags: 'text' });const Ad = Local.model('Ad', adSchema);Ad.createIndexes();