mongodb/mongoid · error

Using #{result} as the field type is not supported. Saving v

Error message

Using #{result} as the field type is not supported. 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.

What it means

Error "Using #{result} as the field type is not supported. 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." thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/fields.rb:925

      #
      # @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.
      #
      # @return [ Class ] The type of the field.
      #
      # @api private
      def unmapped_type(type)
        if 'Boolean' == type.to_s
          Mongoid::Boolean
        else
          type || Object

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/fields.rb:925 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/1efbfbd4ac950d45. Report an issue: GitHub.