mongodb/mongoid · error · Mongoid::Errors::NoDefaultClient
No default client configuration is defined.
Error message
No default client configuration is defined.
What it means
Raised by Mongoid::Config::Validators::Client.validate when the clients configuration hash defines one or more clients but none of them is named :default. Mongoid requires a default client as the fallback for all models and operations that do not name a client explicitly; the faulting input is the clients hash lacking a default key.
Solutions
- Add a default: entry under clients in mongoid.yml
- Rename the intended primary client to :default
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at lib/mongoid/config/validators/client.rb:20 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/6f692b7a385d8f91.
Report an issue: GitHub.
Appendix: source
Thrown at lib/mongoid/config/validators/client.rb:20
module Mongoid
module Config
module Validators
# Validator for client specific configuration.
module Client
extend self
# Standard configuration options.
STANDARD = %i[database hosts username password].freeze
# Validate the client configuration.
#
# @example Validate the client config.
# Client.validate({ default: { hosts: [ "localhost:27017" ] }})
#
# @param [ Hash ] clients The clients config.
def validate(clients)
raise Errors::NoDefaultClient.new(clients.keys) unless clients.has_key?(:default)
clients.each_pair do |name, config|
validate_client_database(name, config)
validate_client_hosts(name, config)
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.View on GitHub (pinned to 0da0e23d71)