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

Malformed $mod argument #{condition}, should have 2 elements

Error message

Malformed $mod argument #{condition}, should have 2 elements

What it means

Error "Malformed $mod argument #{condition}, should have 2 elements" thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/matcher/mod.rb:22

    #
    # @see https://www.mongodb.com/docs/manual/reference/operator/query/mod/
    #
    # @api private
    module Mod
      # Returns whether a value satisfies a $mod expression.
      #
      # @param [ true | false ] exists Not used.
      # @param [ Numeric ] value The value to check.
      # @param [ Array<Numeric> ] condition The $mod condition predicate,
      #   which is a 2-tuple containing the divisor and remainder.
      #
      # @return [ true | false ] Whether the value matches.
      #
      # @api private
      module_function def matches?(_exists, value, condition)
        raise Errors::InvalidQuery, "Unknown $mod argument #{condition}" unless condition.is_a?(Array)
        if condition.length != 2
          raise Errors::InvalidQuery, "Malformed $mod argument #{condition}, should have 2 elements"
        end

        condition[1] == value % condition[0]
      end
    end
  end
end

View on GitHub (pinned to 0da0e23d71)

When it happens

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

Common situations: See trigger scenarios.

Understand the failure class


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