mongodb/mongoid · error · ArgumentError
Criteria#where requires zero or one arguments
Error message
Criteria#where requires zero or one arguments (given #{args.length}) What it means
Raised by Criteria#where when it is called with more than one positional argument. Historically and per MONGOID-4804, where accepts zero or one argument (a Hash selection or a JavaScript string); passing two or more arguments has no defined meaning and is rejected. The faulting input is the args array with length > 1.
Solutions
- Merge conditions into a single hash: where(name: 'x', age: 1)
- Chain multiple where calls for additional criteria
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at lib/mongoid/criteria.rb:518 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/6f57cf5a4993b5ef.
Report an issue: GitHub.
Appendix: source
Thrown at lib/mongoid/criteria.rb:518
# @example Add a javascript selection.
# criteria.where("this.name == 'syd'")
#
# @param [ [ Hash | String ]... ] *args The standard selection
# or javascript string.
#
# @raise [ UnsupportedJavascript ] If provided a string and the criteria
# is embedded.
#
# @return [ Criteria ] The cloned selectable.
def where(*args)
# Historically this method required exactly one argument.
# As of https://jira.mongodb.org/browse/MONGOID-4804 it also accepts
# zero arguments.
# The underlying where implementation that super invokes supports
# any number of arguments, but we don't presently allow multiple
# arguments through this method. This API can be reconsidered in the
# future.
raise ArgumentError, "Criteria#where requires zero or one arguments (given #{args.length})" if args.length > 1
if args.length == 1
expression = args.first
raise Errors::UnsupportedJavascript.new(klass, expression) if expression.is_a?(::String) && embedded?
end
super
end
# Get a version of this criteria without the options.
#
# @example Get the criteria without options.
# criteria.without_options
#
# @return [ Criteria ] The cloned criteria.
def without_options
crit = clone
crit.options.clear
critView on GitHub (pinned to 0da0e23d71)