Module: Mongoid::Matcher::ElemMatchExpression Private

Defined in:
lib/mongoid/matcher/elem_match_expression.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

In-memory matcher used to evaluate whether an $elemMatch predicate matches and individual document. The $elemMatch predicate can be a logical expressions including $and, $or, $nor, and $not. $not can also have a regular expression predicate.

Class Method Summary collapse

Class Method Details

.matches?(document, expr) ⇒ true | false, Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether a document satisfies an $elemMatch expression.

Parameters:

  • document (Mongoid::Document)

    The document.

  • expr (Hash)

    The $elemMatch condition predicate.

Returns:

  • (true | false)

    Whether the document matches.

  • (Boolean)


21
22
23
24
25
26
27
28
29
# File 'lib/mongoid/matcher/elem_match_expression.rb', line 21

module_function def matches?(document, expr)
  Expression.matches?(document, expr)
rescue Mongoid::Errors::InvalidExpressionOperator
  begin
    FieldExpression.matches?(true, document, expr)
  rescue Mongoid::Errors::InvalidFieldOperator => exc
    raise Mongoid::Errors::InvalidElemMatchOperator.new(exc.operator)
  end
end