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 default Mongo Client via 'quarkus.mongodb.database' or the connection string

What it means

The entity class has a @MongoEntity annotation but its clientName attribute is empty (meaning it uses the default Mongo client), and no database could be resolved: neither 'quarkus.mongodb.database' nor the default client's connection string provides a database, and @MongoEntity.database was not set either.

Source

Thrown at extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/BeanUtils.java:71

        }
        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)
                .map(MongoDatabaseResolver::resolve)
                .filter(Predicate.not(String::isBlank));
    }

    private static <T> T firstInstanceWithoutQualifier(Iterable<InstanceHandle<T>> handles,

View on GitHub (pinned to e1c734241f)

Solutions

  1. Set the database on the annotation: @MongoEntity(database="mydb")
  2. Set 'quarkus.mongodb.database=mydb' in application.properties
  3. Embed the database in the default connection string: quarkus.mongodb.connection-string=mongodb://host:27017/mydb

Example fix

// before
@MongoEntity(clientName = "default")
public class Person extends PanacheMongoEntity {}

// after
@MongoEntity(clientName = "default", database = "mydb")
public class Person extends PanacheMongoEntity {}
Defensive patterns

Strategy: validation

Validate before calling

MongoEntity anno = MyEntity.class.getAnnotation(MongoEntity.class);
if (anno == null || anno.database().isEmpty()) {
    throw new IllegalStateException("@MongoEntity(database=...) must be set or quarkus.mongodb.database configured");
}

Try / catch

try {
    entity.persist();
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("@MongoEntity annotation")) {
        log.error("Set database on @MongoEntity or quarkus.mongodb.database", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Entity annotated with @MongoEntity (or @MongoEntity(clientName="")) that omits the database attribute, while application.properties has no 'quarkus.mongodb.database' and the default connection string lacks a /database path segment.

Common situations: Adding @MongoEntity to redirect to a named client later but leaving database unset; copy-pasting annotation templates without the database attribute; removing the database property during config refactoring.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/e985ce605a00951f. Report an issue: GitHub.