Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mongoid

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 case, perfect.

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

like image 430
meow Avatar asked Jun 25 '11 08:06

meow


1 Answers

You should be able to use simple regex for that:

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

Alex

like image 86
Alex Avatar answered Oct 21 '22 16:10

Alex