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

Unknown $type argument: #

Error message

Unknown $type argument: #{condition}

What it means

Raised by Mongoid::Matcher::Type.matches? when the $type condition contains a value that is not a recognized BSON type number (or alias form supported by the server). The faulting input is the unknown condition passed as the $type argument.

Solutions

  1. Use valid BSON type codes (e.g. 1 for Double, 2 for String) or aliases like 'string', 'int'
  2. Check the MongoDB $type documentation for the full list of accepted type identifiers
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/mongoid/matcher/type.rb:26 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/5997e2721d010988. Report an issue: GitHub.

Appendix: source

Thrown at lib/mongoid/matcher/type.rb:26

    module Type
      # Returns whether a value satisfies a $type expression.
      #
      # @param [ true | false ] exists Whether the value exists.
      # @param [ Object ] value The value to check.
      # @param [ Integer | Array<Integer> ] condition The $type condition
      #   predicate which corresponds to the BSON type enumeration.
      #
      # @return [ true | false ] Whether the value matches.
      #
      # @api private
      module_function def matches?(exists, value, condition)
        conditions = case condition
                     when Array
                       condition
                     when Integer
                       [ condition ]
                     else
                       raise Errors::InvalidQuery, "Unknown $type argument: #{condition}"
                     end
        conditions.each do |condition|
          return true if one_matches?(exists, value, condition)
        end
        false
      end

      # Returns whether a value satisfies a single $type expression
      # value.
      #
      # @param [ true | false ] exists Whether the value exists.
      # @param [ Object ] value The value to check.
      # @param [ Integer ] condition The $type condition predicate
      #   which corresponds to the BSON type enumeration.
      #
      # @return [ true | false ] Whether the value matches.
      #
      # @api private

View on GitHub (pinned to 0da0e23d71)