quarkusio/quarkus · error · IllegalArgumentException
The database was not configured for the default Mongo Client
Error message
The database was not configured for the default Mongo Client via 'quarkus.mongodb.database' or the connection string
What it means
MongoDB Panache must resolve a database name for every entity operation. It looks first at the named client's database property, then the default client's database, then the database embedded in the connection string. If none are set and the entity class carries no @MongoEntity annotation, getDatabaseName throws this IllegalArgumentException before any MongoDB call is made.
Source
Thrown at extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/BeanUtils.java:66
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
MongoConfig mongoConfig = config.getConfigMapping(MongoConfig.class);
MongoClientConfig mongoClientConfig = mongoConfig.clients().get(clientBeanName);
if (mongoClientConfig.database().isPresent()) {
return mongoClientConfig.database().get();
}
MongoClientConfig defaultMongoClientConfig = mongoConfig.clients().get(MongoConfig.DEFAULT_CLIENT_NAME);
if (defaultMongoClientConfig.database().isPresent()) {
return defaultMongoClientConfig.database().get();
}
if (mongoClientConfig.connectionString().isPresent()) {
String database = new ConnectionString(mongoClientConfig.connectionString().get()).getDatabase();
if (database != null) {
return database;
}
}
if (mongoEntity == null) {
throw new IllegalArgumentException(
"The database was not configured for the default Mongo Client via 'quarkus.mongodb.database' "
+ "or the connection string");
}
if (mongoEntity.clientName().isEmpty()) {
throw new IllegalArgumentException("The database attribute was not set for the @MongoEntity annotation "
+ "and the database was not configured for the default Mongo Client via 'quarkus.mongodb.database' "
+ "or the connection string");
}
throw new IllegalArgumentException(String.format(
"The database attribute was not set for the @MongoEntity annotation and the database was not configured "
+ "for the named Mongo Client via 'quarkus.mongodb.%s.database' or the connection string",
mongoEntity.clientName()));
}
public static Optional<String> getDatabaseNameFromResolver() {
return Optional.of(Arc.container().select(MongoDatabaseResolver.class))
.filter(Predicate.not(InjectableInstance::isUnsatisfied))
.map(InjectableInstance::get)View on GitHub (pinned to e1c734241f)
Solutions
- Set 'quarkus.mongodb.database=mydb' in application.properties for the default client
- Append the database to the connection string: quarkus.mongodb.connection-string=mongodb://localhost:27017/mydb
- Add @MongoEntity(database="mydb") to the entity class (note the entity's database attribute, not just clientName)
- Inject a MongoDatabaseResolver bean or use a named client config quarkus.mongodb.<client>.database if using a named client
Example fix
// before (application.properties) quarkus.mongodb.connection-string=mongodb://localhost:27017 // after quarkus.mongodb.connection-string=mongodb://localhost:27017 quarkus.mongodb.database=mydb
Defensive patterns
Strategy: validation
Validate before calling
if (config.getOptionalValue("quarkus.mongodb.database", String.class).isEmpty()
&& config.getOptionalValue("quarkus.mongodb.connection-string", String.class)
.map(cs -> !new ConnectionString(cs).getDatabase().isEmpty()).orElse(false) == false) {
throw new IllegalStateException("Configure quarkus.mongodb.database or a connection string with /database");
} Try / catch
try {
repository.listAll();
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("database was not configured")) {
log.error("MongoDB database not configured: set quarkus.mongodb.database", e);
}
throw e;
} Prevention
- Always set quarkus.mongodb.database in application.properties for every environment (dev/test/prod profiles)
- Prefer connection strings that include the /database segment
- Add a startup smoke test that performs a trivial repository read and fails fast on config errors
When it happens
Trigger: Calling any Panache MongoDB operation (persist/find/list, etc.) on an entity class that has no @MongoEntity annotation (mongoEntity == null) while 'quarkus.mongodb.database' is unset and the client's connection string contains no database part.
Common situations: Fresh project where application.properties only has quarkus.mongodb.connection-string=mongodb://localhost:27017 (no /dbname suffix); developers assuming Panache derives the database from the entity class name; switching from a connection string with a database to one without.
Related errors
- Mongo client named '%s' not found
- mongo config is missing for creating mongo client.
- Illegal read preference configured in the @MongoEntity anno
- The database attribute was not set for the @MongoEntity anno
- The database attribute was not set for the @MongoEntity anno
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/308fce4c646b5060.
Report an issue: GitHub.