mongodb/mongoid · error · Mongoid::Errors::InvalidQuery
Invalid value for $#{operator_name} argument: negative integ
Error message
Invalid value for $#{operator_name} argument: negative integers are not allowed: #{condition} What it means
Error "Invalid value for $#{operator_name} argument: negative integers are not allowed: #{condition}" thrown in mongodb/mongoid.
Source
Thrown at lib/mongoid/matcher/bits.rb:30
# predicate as a bitmask or position list.
#
# @return [ true | false ] Whether the value matches.
#
# @api private
def matches?(_exists, value, condition)
case value
when BSON::Binary
value = value.data.split('').map { |n| '%02x' % n.ord }.join.to_i(16)
end
case condition
when Array
array_matches?(value, condition)
when BSON::Binary
int_cond = condition.data.split('').map { |n| '%02x' % n.ord }.join.to_i(16)
int_matches?(value, int_cond)
when Integer
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}"View on GitHub (pinned to 0da0e23d71)
When it happens
Trigger: Thrown at lib/mongoid/matcher/bits.rb:30 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/6927c1af515877ad.
Report an issue: GitHub.