quarkusio/quarkus · error · IllegalArgumentException
The database attribute was not set for the @MongoEntity anno
Error message
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
What it means
The entity's @MongoEntity points at a named Mongo client (clientName is non-empty), but neither the annotation's database attribute, the named client's 'quarkus.mongodb.<clientName>.database' property, nor that client's connection string provides a database name.
Source
Thrown at extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/BeanUtils.java:75
}
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)
.map(MongoDatabaseResolver::resolve)
.filter(Predicate.not(String::isBlank));
}
private static <T> T firstInstanceWithoutQualifier(Iterable<InstanceHandle<T>> handles,
Class<? extends Annotation> qualifier) {
for (InstanceHandle<T> handle : handles) {
InjectableBean<T> bean = handle.getBean();
boolean match = false;View on GitHub (pinned to e1c734241f)
Solutions
- Set 'quarkus.mongodb.<clientName>.database=mydb' in application.properties (e.g. quarkus.mongodb.orders.database)
- Set the database on the annotation: @MongoEntity(clientName="orders", database="mydb")
- Embed the database in the named client's connection string: quarkus.mongodb.orders.connection-string=mongodb://host:27017/mydb
Example fix
// before (application.properties) quarkus.mongodb.orders.connection-string=mongodb://orders-host:27017 // after quarkus.mongodb.orders.connection-string=mongodb://orders-host:27017 quarkus.mongodb.orders.database=ordersdb
Defensive patterns
Strategy: validation
Validate before calling
MongoEntity anno = MyEntity.class.getAnnotation(MongoEntity.class);
String client = anno != null ? anno.clientName() : "";
if (!client.isEmpty()
&& config.getOptionalValue("quarkus.mongodb." + client + ".database", String.class).isEmpty()) {
throw new IllegalStateException("Named client '" + client + "' has no database configured");
} Try / catch
try {
repository.find("byName", name).firstResult();
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("named Mongo Client")) {
log.error("Missing quarkus.mongodb.<client>.database for named client", e);
}
throw e;
} Prevention
- For every named client (quarkus.mongodb.<name>.*), also define quarkus.mongodb.<name>.database
- Double-check clientName spelling matches the config key exactly
- Use Quarkus dev services / config mapping validation at startup to catch unconfigured named clients early
When it happens
Trigger: Entity annotated @MongoEntity(clientName="orders") with no database attribute, while 'quarkus.mongodb.orders.database' is unset and 'quarkus.mongodb.orders.connection-string' has no /database path part.
Common situations: Multi-client setups where developers configure the named client's hosts but forget its database; copying the default client's config pattern and omitting the per-client database; typos in the client property name so the named config is never picked up.
Related errors
- <errorMessage>.formatted(clientName) (required Liquibase Mon
- Illegal read preference configured in the @MongoEntity anno
- The database was not configured for the default Mongo Client
- The database attribute was not set for the @MongoEntity anno
- Config property 'quarkus.mongodb.database' must be defined w
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/543e7ef2b6e50564.
Report an issue: GitHub.