mongodb/mongoid · error · Mongoid::Errors::NoClientDatabase
No database provided for client configuration
Error message
No database provided for client configuration: :%{name}. What it means
Raised by the private validate_client_database helper during client configuration validation when a client entry provides neither a :database key nor a :uri (a URI can imply the database). The faulting input is the config hash for client :name missing both.
Solutions
- Add database: my_db to the client configuration in mongoid.yml
- Provide a uri: that includes the database in the connection string
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at lib/mongoid/config/validators/client.rb:43 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/2ae7a1b5fa7a1dec.
Report an issue: GitHub.
Appendix: source
Thrown at lib/mongoid/config/validators/client.rb:43
validate_client_uri(name, config)
end
end
private
# Validate that the client config has database.
#
# @api private
#
# @example Validate the client has database.
# validator.validate_client_database(:default, {})
#
# @param [ String | Symbol ] name The config key.
# @param [ Hash ] config The configuration.
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 aView on GitHub (pinned to 0da0e23d71)