mongodb/mongoid · error · Mongoid::Errors::InvalidQuery
Unknown $mod argument #
Error message
Unknown $mod argument #{condition} What it means
Raised by the in-memory $mod matcher when the condition operand is not recognized as a valid $mod argument form (a two-element array of divisor and remainder). This is the catch-all rejection for wrong operand shapes.
Solutions
- Provide $mod as [divisor, remainder], e.g. { qty: { '$mod' => [4, 0] } }
- Ensure the operand is an Array of two Numeric values
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at lib/mongoid/matcher/mod.rb:20 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/84f524fb090212b7.
Report an issue: GitHub.
Appendix: source
Thrown at lib/mongoid/matcher/mod.rb:20
module Matcher
# In-memory matcher for $mod expression.
#
# @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)