开发者

Mongoid: Querying for documents for certain fields which contains a given string

开发者 https://www.devze.com 2023-03-15 13:49 出处:网络
I am a little stuck here (mongoid docs does not seem to give an answer) Question.where(:text.contains=>\"perfect\")

I am a little stuck here (mongoid docs does not seem to give an answer)

Question.where(:text.contains=>"perfect")

I would like to find questions which text field contains a given word, in this ca开发者_StackOverflow社区se, perfect.

What is the correct query here, and how can i improve the performance of such queries?


You should be able to use simple regex for that:

Question.where(:text => /perfect/)

Alex

0

精彩评论

暂无评论...
验证码 换一张
取 消