mongodbmongoidmongoid5

How to create text index in mongoid 5?


I have this in my model

index({company_name: 1, first_name: 1, last_name: 1 })

Model.text_search 'something'

gives this error

Mongo::Error::OperationFailure: text index required for $text query


Solution

  • I found the solution

    index({company_name: 'text', first_name: 'text', last_name: 'text' })

    You just have to pass 'text' instead of 1.