Mongoid: query for documents for specific fields containing a given string

I'm a little stuck here (mongoid docs don't seem to give an answer)

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

I would like to find questions whose text box contains the given word, in this case perfect.

What is the correct query here and how can the performance of such queries be improved?

+6
source share
1 answer

You can use a simple regular expression for this:

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

Alex

+16
source

Source: https://habr.com/ru/post/891343/


All Articles