mongodb/mongoid · error · Mongoid::Errors::InvalidQuery
Invalid type for $# argument: not representable as an…
Error message
Invalid type for $#{operator_name} argument: not representable as an integer: #{condition} What it means
Raised by the in-memory bitwise matcher when a Float condition has a fractional part (e.g. 50.1). Bitwise operators require integer operands, so a non-integral float cannot be represented as a mask or position list.
Solutions
- Pass an Integer or a whole-number Float (e.g. 50.0) as the bitwise condition
- Round or truncate the value beforehand if the fractional part is noise
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at lib/mongoid/matcher/bits.rb:47 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/bda9a46a1bb8813b.
Report an issue: GitHub.
Appendix: source
Thrown at lib/mongoid/matcher/bits.rb:47
if condition < 0
raise Errors::InvalidQuery,
"Invalid value for $#{operator_name} argument: negative integers are not allowed: #{condition}"
end
int_matches?(value, condition)
when Float
# Allow floats that are whole numbers (e.g. 50.0), but reject those
# with a fractional part (e.g. 50.1) since bitwise ops require integers.
int_cond = condition.to_i
if int_cond == condition
if int_cond < 0
raise Errors::InvalidQuery,
"Invalid value for $#{operator_name} argument: negative numbers are not allowed: #{condition}"
end
int_matches?(value, int_cond)
else
raise Errors::InvalidQuery,
"Invalid type for $#{operator_name} argument: not representable as an integer: #{condition}"
end
else
raise Errors::InvalidQuery, "Invalid type for $#{operator_name} argument: #{condition}"
end
end
# Returns the name of the expression operator.
#
# @return [ String ] The operator name.
#
# @api private
module_function def operator_name
name.sub(/.*::/, '').sub(/\A(.)/) { |l| l.downcase }
end
end
end
endView on GitHub (pinned to 0da0e23d71)