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

Invalid option : provided for field : .

Error message

Invalid option :%{option} provided for field :%{name}.

What it means

Raised by Macro.validate_options when a field or association is declared with an option key that is not in the list of allowed options for that macro. Fires at class-load time when the field/association DSL is evaluated.

Solutions

  1. Remove the invalid option from the field or association declaration
  2. Check the Mongoid documentation for the set of valid options for the macro being used
  3. Watch for typos in option names such as :localize vs :localized
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/mongoid/fields/validators/macro.rb:106 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/5d24797029e2d1cb. Report an issue: GitHub.

Appendix: source

Thrown at lib/mongoid/fields/validators/macro.rb:106

          Mongoid.logger.warn("Overwriting existing field #{name} in class #{klass.name}.") if Mongoid.logger
        end

        # Validate that the field options are allowed.
        #
        # @api private
        #
        # @example Validate the field options.
        #   Macro.validate_options(Model, :name, { localized: true })
        #
        # @param [ Class ] klass The model class.
        # @param [ Symbol ] name The field name.
        # @param [ Hash ] options The provided options.
        #
        # @raise [ Errors::InvalidFieldOption ] If an option is invalid.
        def validate_options(klass, name, options)
          options.keys.each do |option|
            if !OPTIONS.include?(option) && !Fields.options.include?(option)
              raise Errors::InvalidFieldOption.new(klass, name, option, OPTIONS)
            end

            Mongoid::Warnings.warn_symbol_type_deprecated if option == :type && options[option] == Symbol
          end
        end
      end
    end
  end
end

View on GitHub (pinned to 0da0e23d71)