mongodb/mongoid · error · Mongoid::Errors::InvalidQuery

$nor argument must be a non-empty array: #{Errors::InvalidQu

Error message

$nor argument must be a non-empty array: #{Errors::InvalidQuery.truncate_expr(expr)}

What it means

Error "$nor argument must be a non-empty array: #{Errors::InvalidQuery.truncate_expr(expr)}" thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/matcher/nor.rb:23

    # @see https://www.mongodb.com/docs/manual/reference/operator/query/nor/
    #
    # @api private
    module Nor
      # Returns whether a document satisfies a $nor expression.
      #
      # @param [ Mongoid::Document ] document The document.
      # @param [ Array<Hash> ] expr The $nor conditions.
      #
      # @return [ true | false ] Whether the document matches.
      #
      # @api private
      module_function def matches?(document, expr)
        unless expr.is_a?(Array)
          raise Errors::InvalidQuery, "$nor argument must be an array: #{Errors::InvalidQuery.truncate_expr(expr)}"
        end

        if expr.empty?
          raise Errors::InvalidQuery, "$nor argument must be a non-empty array: #{Errors::InvalidQuery.truncate_expr(expr)}"
        end

        expr.each do |sub_expr|
          return false if Expression.matches?(document, sub_expr)
        end

        expr.any?
      end
    end
  end
end

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/matcher/nor.rb:23 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23). Data as JSON: /api/errors/a117d8cf74d8f5c9. Report an issue: GitHub.