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

Invalid field type %{type_inspection} for field '%{field}' o

Error message

Invalid field type %{type_inspection} for field '%{field}' on model '%{klass}'.

What it means

Error "Invalid field type %{type_inspection} for field '%{field}' on model '%{klass}'." thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/fields.rb:916

        return Fields::Encrypted.new(name, opts) if options[:encrypt]

        Fields::Standard.new(name, opts)
      end

      # Get the class for the given type.
      #
      # @param [ Symbol ] name The name of the field.
      # @param [ Symbol | Class ] type The type of the field.
      #
      # @return [ Class ] The type of the field.
      #
      # @raise [ Mongoid::Errors::InvalidFieldType ] if given an invalid field
      #   type.
      #
      # @api private
      def retrieve_and_validate_type(name, type)
        result = TYPE_MAPPINGS[type] || unmapped_type(type)
        raise Errors::InvalidFieldType.new(self, name, type) unless result.is_a?(Class)

        if unsupported_type?(result)
          warn_message = "Using #{result} as the field type is not supported. "
          if result == BSON::Decimal128
            warn_message += 'In BSON <= 4, the BSON::Decimal128 type will work as expected for both storing and querying, but will return a BigDecimal on query in BSON 5+. To use literal BSON::Decimal128 fields with BSON 5, set Mongoid.allow_bson5_decimal128 to true.'
          else
            warn_message += 'Saving values of this type to the database will work as expected, however, querying them will return a value of the native Ruby Integer type.'
          end
          Mongoid.logger.warn(warn_message)
        end

        result
      end

      # Returns the type of the field if the type was not in the TYPE_MAPPINGS
      # hash.
      #
      # @param [ Symbol | Class ] type The type of the field.

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/fields.rb:916 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/5a386bbeca8a4979. Report an issue: GitHub.