mongodb/mongoid · error · Mongoid::Errors::InvalidQuery
$in argument must be an array: #
Error message
$in argument must be an array: #{Errors::InvalidQuery.truncate_expr(condition)} What it means
Raised by Mongoid::Matcher::In.matches? when the $in condition is not an Array. MongoDB's $in operator takes a list of candidate values (possibly with regexps); the faulting input is the non-Array condition.
Solutions
- Wrap the candidate values in an Array: { status: { '$in' => ['a', 'b'] } }
- Use direct equality for matching a single value
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at lib/mongoid/matcher/in.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/49d3c075936c1072.
Report an issue: GitHub.
Appendix: source
Thrown at lib/mongoid/matcher/in.rb:20
module Matcher
# In-memory matcher for $in expression.
#
# @see https://www.mongodb.com/docs/manual/reference/operator/query/in/
#
# @api private
module In
# Returns whether a value satisfies an $in expression.
#
# @param [ true | false ] exists Not used.
# @param [ Object ] value The value to check.
# @param [ Array<Object> ] condition The $in condition predicate.
#
# @return [ true | false ] Whether the value matches.
#
# @api private
module_function def matches?(_exists, value, condition)
unless condition.is_a?(Array)
raise Errors::InvalidQuery, "$in argument must be an array: #{Errors::InvalidQuery.truncate_expr(condition)}"
end
if value.is_a?(Array) && value.any? do |v|
condition.any? do |c|
EqImplWithRegexp.matches?('$in', v, c)
end
end
return true
end
condition.any? do |c|
EqImplWithRegexp.matches?('$in', value, c)
end
end
end
end
end
View on GitHub (pinned to 0da0e23d71)