{"record":{"id":"5a386bbeca8a4979","repo":"mongodb/mongoid","slug":"invalid-field-type-type-inspection-for-field","errorCode":null,"errorMessage":"Invalid field type %{type_inspection} for field '%{field}' on model '%{klass}'.","messagePattern":"Invalid field type %(.+?) for field '%(.+?)' on model '%(.+?)'\\.","errorType":"exception","errorClass":"Mongoid::Errors::InvalidFieldType","httpStatus":null,"severity":"error","filePath":"lib/mongoid/fields.rb","lineNumber":916,"sourceCode":"        return Fields::Encrypted.new(name, opts) if options[:encrypt]\n\n        Fields::Standard.new(name, opts)\n      end\n\n      # Get the class for the given type.\n      #\n      # @param [ Symbol ] name The name of the field.\n      # @param [ Symbol | Class ] type The type of the field.\n      #\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.","sourceCodeStart":898,"sourceCodeEnd":934,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/fields.rb#L898-L934","documentation":"Raised by retrieve_and_validate_type when the :type option of a field declaration cannot be mapped to a known field class (via TYPE_MAPPINGS or unmapped_type). The error fires at class-load time while the field is being defined.","triggerScenarios":"Thrown at lib/mongoid/fields.rb:916 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a supported field type such as String, Integer, Float, Date, Time, BSON::ObjectId, or Array","Pass the Class itself rather than a string or symbol if the type is custom","Define a custom type that includes Mongoid::Fields::Serializable"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","contentChangedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}