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

No hosts provided for client configuration

Error message

No hosts provided for client configuration: :%{name}.

What it means

Raised by the private validate_client_hosts helper during client configuration validation when a client entry provides neither :hosts nor a :uri, leaving Mongoid unable to determine which servers to connect to. The faulting input is the config hash for client :name missing both.

Solutions

  1. Add hosts: [ localhost:27017 ] to the client configuration
  2. Provide a uri: connection string containing the host(s)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/mongoid/config/validators/client.rb:58 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/5a9a22b831115db6. Report an issue: GitHub.

Appendix: source

Thrown at lib/mongoid/config/validators/client.rb:58

        def validate_client_database(name, config)
          return unless no_database_or_uri?(config)

          raise Errors::NoClientDatabase.new(name, config)
        end

        # Validate that the client config has hosts.
        #
        # @api private
        #
        # @example Validate the client has hosts.
        #   validator.validate_client_hosts(:default, {})
        #
        # @param [ String | Symbol ] name The config key.
        # @param [ Hash ] config The configuration.
        def validate_client_hosts(name, config)
          return unless no_hosts_or_uri?(config)

          raise Errors::NoClientHosts.new(name, config)
        end

        # Validate that not both a uri and standard options are provided for a
        # single client.
        #
        # @api private
        #
        # @example Validate the uri and options.
        #   validator.validate_client_uri(:default, {})
        #
        # @param [ String | Symbol ] name The config key.
        # @param [ Hash ] config The configuration.
        def validate_client_uri(name, config)
          return unless both_uri_and_standard?(config)

          raise Errors::MixedClientConfiguration.new(name, config)
        end

View on GitHub (pinned to 0da0e23d71)