quarkusio/quarkus · critical · IllegalArgumentException

Config property 'quarkus.mongodb.database' must be defined w

Error message

Config property 'quarkus.mongodb.database' must be defined when no database exist in the connection string

What it means

LiquibaseMongodbFactory.createLiquibase needs a database name for the Liquibase MongoDB database handle. It first checks the quarkus.mongodb.database config; if absent it tries to extract the database from the connection string via a regex, and if neither exists it throws this IllegalArgumentException. The message is explicit: MongoDB connection strings can be database-less (e.g. mongodb://host:27017), so the database must be configured.

Source

Thrown at extensions/liquibase/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/LiquibaseMongodbFactory.java:122

        if (changeLog.startsWith("classpath:")) {
            return StringUtil.changePrefix(changeLog, "classpath:", "");
        }

        return changeLog;
    }

    public Liquibase createLiquibase() {
        try (ResourceAccessor resourceAccessor = resolveResourceAccessor()) {
            MongoClients mongoClients = Arc.container().instance(MongoClients.class).get();
            String parsedChangeLog = parseChangeLog(liquibaseMongodbBuildTimeConfig.changeLog());
            String connectionString = mongoClientConfig.connectionString().orElse("mongodb://localhost:27017");
            Matcher matcher = HAS_DB.matcher(connectionString);
            Optional<String> maybeDatabase = mongoClientConfig.database();
            if (maybeDatabase.isEmpty()) {
                if (matcher.matches() && !StringUtil.isNullOrEmpty(matcher.group("db"))) {
                    maybeDatabase = Optional.of(matcher.group("db"));
                } else {
                    throw new IllegalArgumentException("Config property 'quarkus.mongodb.database' must " +
                            "be defined when no database exist in the connection string");
                }
            }
            Database database = createDatabase(mongoClients, clientName, maybeDatabase.get());
            if (liquibaseMongodbConfig.liquibaseCatalogName().isPresent()) {
                database.setLiquibaseCatalogName(liquibaseMongodbConfig.liquibaseCatalogName().get());
            }
            if (liquibaseMongodbConfig.liquibaseSchemaName().isPresent()) {
                database.setLiquibaseSchemaName(liquibaseMongodbConfig.liquibaseSchemaName().get());
            }
            if (liquibaseMongodbConfig.liquibaseTablespaceName().isPresent()) {
                database.setLiquibaseTablespaceName(liquibaseMongodbConfig.liquibaseTablespaceName().get());
            }
            if (liquibaseMongodbConfig.defaultCatalogName().isPresent()) {
                database.setDefaultCatalogName(liquibaseMongodbConfig.defaultCatalogName().get());
            }
            if (liquibaseMongodbConfig.defaultSchemaName().isPresent()) {
                database.setDefaultSchemaName(liquibaseMongodbConfig.defaultSchemaName().get());

View on GitHub (pinned to e1c734241f)

Solutions

  1. Set the database in application.properties, e.g. quarkus.mongodb.database=mydb (or quarkus.mongodb.<client-name>.database for a named client)
  2. Alternatively append the database to the connection string: mongodb://user:pass@host:27017/mydb or mongodb+srv://cluster/host/mydb
  3. If multiple clients exist, make sure the config is set for the client Liquibase is targeting, not just the default
  4. Confirm the Liquibase startup actions are intended for that client and that its config block exists

Example fix

# before
quarkus.mongodb.connection-string=mongodb://localhost:27017
# after
quarkus.mongodb.connection-string=mongodb://localhost:27017
quarkus.mongodb.database=inventory
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast at startup if the DB name is neither in config nor in the connection string
String cs = config.getValue("quarkus.mongodb.connection-string");
String db = config.getOptionalValue("quarkus.mongodb.database", String.class).orElse(null);
String dbFromCs = null;
if (cs != null) {
    java.net.URI u = java.net.URI.create(cs);
    String p = u.getPath();
    if (p != null && p.length() > 1) dbFromCs = p.substring(1);
}
if ((db == null || db.isBlank()) && (dbFromCs == null || dbFromCs.isBlank())) {
    throw new IllegalArgumentException("Set quarkus.mongodb.database or append the database to the connection string");
}

Try / catch

try {
    liquibaseMongodbFactory.createLiquibase();
} catch (IllegalArgumentException e) {
    if (e.getMessage() != null && e.getMessage().contains("quarkus.mongodb.database")) {
        // supply the database name or append it to the connection string
    }
    throw e;
}

Prevention

When it happens

Trigger: quarkus.liquibase-mongodb.start-actions is enabled, the connection string in quarkus.mongodb.connection-string has no database segment, and quarkus.mongodb.database is not set — LiquibaseMongodbFactory.createLiquibase (invoked from doStartActions at startup) throws.

Common situations: Developers configure only mongodb://localhost:27017 without quarkus.mongodb.database; connecting to Atlas with a SRV string lacking the /database part; a named client (quarkus.mongodb.<name>.) where only the default config was filled in; enabling Liquibase MongodbStartActions on an app that never needed a default DB.

Related errors


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