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

  1. Set 'quarkus.mongodb.database=mydb' in application.properties for the default client
  2. Append the database to the connection string: quarkus.mongodb.connection-string=mongodb://localhost:27017/mydb
  3. Add @MongoEntity(database="mydb") to the entity class (note the entity's database attribute, not just clientName)
  4. 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

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


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