mongodb/mongoid · error · Mongoid::Errors::CriteriaArgumentRequired

Calling Criteria methods with nil arguments is not allowed.

Error message

Calling Criteria methods with nil arguments is not allowed.

What it means

Error "Calling Criteria methods with nil arguments is not allowed." thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/criteria/queryable/selectable.rb:44

        #
        # @example Add the criterion.
        #   selectable.all(field: [ 1, 2 ])
        #
        # @example Execute an $all in a where query.
        #   selectable.where(:field.all => [ 1, 2 ])
        #
        # @param [ Hash... ] *criteria The key value pair(s) for $all matching.
        #
        # @return [ Selectable ] The cloned selectable.
        def all(*criteria)
          if criteria.empty?
            return clone.tap do |query|
              query.reset_strategies!
            end
          end

          criteria.inject(clone) do |query, condition|
            raise Errors::CriteriaArgumentRequired, :all if condition.nil?

            condition = expand_condition_to_array_values(condition)

            if strategy
              send(strategy, condition, '$all')
            else
              condition.inject(query) do |_query, (field, value)|
                v = { '$all' => value }
                v = { '$not' => v } if negating?
                _query.add_field_expression(field.to_s, v)
              end
            end
          end.reset_strategies!
        end
        alias all_in all
        key :all, :union, '$all'

        # Add the $and criterion.

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/criteria/queryable/selectable.rb:44 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/ff8c7d2e7936700f. Report an issue: GitHub.