mongodb/mongoid · error · ArgumentError

Criteria#where requires zero or one arguments (given #{args.

Error message

Criteria#where requires zero or one arguments (given #{args.length})

What it means

Error "Criteria#where requires zero or one arguments (given #{args.length})" thrown in mongodb/mongoid.

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
      crit

View on GitHub (pinned to 0da0e23d71)

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.