0

I recently started to use Mongodb with rails so I don't know if is possible to do a NoSQL query like this:

Model.where("lower(first_name || ' ' || last_name) LIKE ?", "%#{search.downcase}%")

I want to type a search with first name and last name in the same string, for example: "John Smith"

Is this possible with Mongoid querying?

Community
  • 1
  • 1
caiobm4
  • 235
  • 1
  • 7

1 Answers1

0

You need to use javascript expressions, see this page:

http://docs.mongodb.org/manual/reference/operator/query/where/

  • 2
    It works! `Model.where("this.first_name this.last_name" == /search/i)`, thank you! – caiobm4 Sep 08 '14 at 20:07
  • Sorry but the correct code is: `Model.where("this.first_name + ' ' + this.last_name == '#{search}'")`, and yet i have not succeeded use Regex instead String – caiobm4 Sep 08 '14 at 22:22