Method: Mongoid::Criteria::Queryable::Selectable#or

Defined in:
lib/mongoid/criteria/queryable/selectable.rb

#or(*criteria) ⇒ Selectable

Creates a disjunction using $or from the existing criteria in the receiver and the provided arguments.

This behavior (receiver becoming one of the disjunction operands) matches ActiveRecord’s or behavior.

Use any_of to add a disjunction of the arguments as an additional constraint to the criteria already existing in the receiver.

Each argument can be a Hash, a Criteria object, an array of Hash or Criteria objects, or a nested array. Nested arrays will be flattened and can be of any depth. Passing arrays is deprecated.

Examples:

Add the $or selection where both fields must have the specified values.

selectable.or(field: 1, field: 2)

Add the $or selection where either value match is sufficient.

selectable.or({field: 1}, {field: 2})

Same as previous example but using the deprecated array wrap.

selectable.or([{field: 1}, {field: 2}])

Same as previous example, also deprecated.

selectable.or([{field: 1}], [{field: 2}])

Parameters:

  • *criteria ([ Hash | Criteria | Array<Hash | Criteria> ]...)

    Multiple key/value pair matches or Criteria objects, or arrays thereof. Passing arrays is deprecated.

Returns:



644
645
646
# File 'lib/mongoid/criteria/queryable/selectable.rb', line 644

def or(*criteria)
  _mongoid_add_top_level_operation('$or', criteria)
end