Method: Mongoid::Criterion::Inclusion#where

Defined in:
lib/mongoid/criterion/inclusion.rb

#where(selector = nil) ⇒ Object

Adds a criterion to the Criteria that specifies values that must be matched in order to return results. This is similar to a SQL “WHERE” clause. This is the actual selector that will be provided to MongoDB, similar to the Javascript object that is used when performing a find() in the MongoDB console.

Options:

selectior: A Hash that must match the attributes of the Document.

Example:

criteria.where(:field1 => "value1", :field2 => 15)

Returns: self



81
82
83
84
85
86
87
88
89
# File 'lib/mongoid/criterion/inclusion.rb', line 81

def where(selector = nil)
  case selector
  when String
    @selector.update("$where" => selector)
  else
    @selector.update(selector ? selector.expand_complex_criteria : {})
  end
  self
end