mongodb/mongoid · error · Mongoid::Errors::MixedClientConfiguration
Both uri and standard configuration options defined for…
Error message
Both uri and standard configuration options defined for client: '%{name}'. What it means
Raised by the private validate_client_uri helper when a client configuration defines both a :uri and one or more standard options (:database, :hosts, :username, :password). The two forms are mutually exclusive because the URI already encodes them; the faulting input is the ambiguous client config hash.
Solutions
- Use either uri: alone or the standard hosts/database/options form, not both
- Move options such as read preference consistently into the uri or the options hash
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at lib/mongoid/config/validators/client.rb:74 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/4f87c6d1b88ecd26.
Report an issue: GitHub.
Appendix: source
Thrown at lib/mongoid/config/validators/client.rb:74
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
# Return true if the configuration has no database or uri option
# defined.
#
# @api private
#
# @example Validate the options.
# validator.no_database_or_uri?(config)
#
# @param [ Hash ] config The configuration options.
#
# @return [ true | false ] If no database or uri is defined.
def no_database_or_uri?(config)
!config.has_key?(:database) && !config.has_key?(:uri)
end
# Return true if the configuration has no hosts or uri optionView on GitHub (pinned to 0da0e23d71)