如何在 mongoid 5 中创建文本索引?
How to create text index in mongoid 5?
我的模型中有这个
index({company_name: 1, first_name: 1, last_name: 1 })
Model.text_search 'something'
出现这个错误
Mongo::Error::OperationFailure: text index required for $text query
我找到了解决方案
index({company_name: 'text', first_name: 'text', last_name: 'text' })
你只需要传递 'text' 而不是 1.
我的模型中有这个
index({company_name: 1, first_name: 1, last_name: 1 })
Model.text_search 'something'
出现这个错误
Mongo::Error::OperationFailure: text index required for $text query
我找到了解决方案
index({company_name: 'text', first_name: 'text', last_name: 'text' })
你只需要传递 'text' 而不是 1.