{"record":{"id":"dbb454f23662e789","repo":"mongodb/mongoid","slug":"defining-a-field-named-field-is-not-allowed","errorCode":null,"errorMessage":"Defining a field named '%{field}' is not allowed.","messagePattern":"Defining a field named '%(.+?)' is not allowed\\.","errorType":"exception","errorClass":"Mongoid::Errors::InvalidField","httpStatus":null,"severity":"error","filePath":"lib/mongoid/fields/validators/macro.rb","lineNumber":66,"sourceCode":"          [ name, :\"#{name}?\", :\"#{name}=\" ].each do |n|\n            raise Errors::InvalidRelation.new(klass, n) if Mongoid.destructive_fields.include?(n)\n          end\n        end\n\n        # Determine if the field name is valid, if not raise an error.\n        #\n        # @example Check the field name.\n        #   Macro.validate_field_name(Model, :name)\n        #\n        # @param [ Class ] klass The model class.\n        # @param [ Symbol ] name The field name.\n        #\n        # @raise [ Errors::InvalidField ] If the name is not allowed.\n        #\n        # @api private\n        def validate_field_name(klass, name)\n          [ name, :\"#{name}?\", :\"#{name}=\" ].each do |n|\n            raise Errors::InvalidField.new(klass, name, n) if Mongoid.destructive_fields.include?(n)\n          end\n        end\n\n        private\n\n        # Determine if the field name is unique, if not raise an error.\n        #\n        # @example Check the field name.\n        #   Macro.validate_name_uniqueness(Model, :name, {})\n        #\n        # @param [ Class ] klass The model class.\n        # @param [ Symbol ] name The field name.\n        # @param [ Hash ] options The provided options.\n        #\n        # @raise [ Errors::InvalidField ] If the name is not allowed.\n        #\n        # @api private\n        def validate_name_uniqueness(klass, name, options)","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/fields/validators/macro.rb#L48-L84","documentation":"Error \"Defining a field named '%{field}' is not allowed.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/fields/validators/macro.rb:66 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"}