{"record":{"id":"1efbfbd4ac950d45","repo":"mongodb/mongoid","slug":"using-result-as-the-field-type-is-not-supported","errorCode":null,"errorMessage":"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.","messagePattern":"Using #(.+?) 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\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/mongoid/fields.rb","lineNumber":925,"sourceCode":"      #\n      # @return [ Class ] The type of the field.\n      #\n      # @raise [ Mongoid::Errors::InvalidFieldType ] if given an invalid field\n      #   type.\n      #\n      # @api private\n      def retrieve_and_validate_type(name, type)\n        result = TYPE_MAPPINGS[type] || unmapped_type(type)\n        raise Errors::InvalidFieldType.new(self, name, type) unless result.is_a?(Class)\n\n        if unsupported_type?(result)\n          warn_message = \"Using #{result} as the field type is not supported. \"\n          if result == BSON::Decimal128\n            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.'\n          else\n            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.'\n          end\n          Mongoid.logger.warn(warn_message)\n        end\n\n        result\n      end\n\n      # Returns the type of the field if the type was not in the TYPE_MAPPINGS\n      # hash.\n      #\n      # @param [ Symbol | Class ] type The type of the field.\n      #\n      # @return [ Class ] The type of the field.\n      #\n      # @api private\n      def unmapped_type(type)\n        if 'Boolean' == type.to_s\n          Mongoid::Boolean\n        else\n          type || Object","sourceCodeStart":907,"sourceCodeEnd":943,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/fields.rb#L907-L943","documentation":"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.","triggerScenarios":"Thrown at lib/mongoid/fields.rb:925 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}