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

Invalid configuration file

Error message

Invalid configuration file: %{path}.

What it means

After ERB processing and safe YAML loading, the configuration did not yield a usable Hash of settings for the environment — typically a malformed YAML structure or a wrong environment key. Raised with the file path.

Solutions

  1. Fix the YAML structure so the environment key maps to a Hash of settings
  2. Verify the environment name exists as a top-level key in mongoid.yml
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/mongoid/config/environment.rb:64 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/8f2f536352e19153. Report an issue: GitHub.

Appendix: source

Thrown at lib/mongoid/config/environment.rb:64

        env = environment ? environment.to_s : env_name

        contents = File.read(path)
        raise Mongoid::Errors::EmptyConfigFile.new(path) if contents.empty?

        # These are the classes that can be used in a Mongoid
        # configuration file in addition to standard YAML types.
        permitted_classes = [
          # Symbols occur as values for read preference, for example.
          Symbol,
          # BSON::Binary occur as keyId values for FLE (more precisely,
          # the keyIds are UUIDs).
          BSON::Binary
        ]

        result = ERB.new(contents).result
        data = YAML.safe_load(result, permitted_classes: permitted_classes, aliases: true)

        raise Mongoid::Errors::InvalidConfigFile.new(path) unless data.is_a?(Hash)

        data[env]
      end
    end
  end
end

View on GitHub (pinned to 0da0e23d71)