{"record":{"id":"308fce4c646b5060","repo":"quarkusio/quarkus","slug":"the-database-was-not-configured-for-the-default-mo","errorCode":null,"errorMessage":"The database was not configured for the default Mongo Client via 'quarkus.mongodb.database' or the connection string","messagePattern":"The database was not configured for the default Mongo Client via 'quarkus\\.mongodb\\.database' or the connection string","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/BeanUtils.java","lineNumber":66,"sourceCode":"        SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);\n        MongoConfig mongoConfig = config.getConfigMapping(MongoConfig.class);\n        MongoClientConfig mongoClientConfig = mongoConfig.clients().get(clientBeanName);\n        if (mongoClientConfig.database().isPresent()) {\n            return mongoClientConfig.database().get();\n        }\n        MongoClientConfig defaultMongoClientConfig = mongoConfig.clients().get(MongoConfig.DEFAULT_CLIENT_NAME);\n        if (defaultMongoClientConfig.database().isPresent()) {\n            return defaultMongoClientConfig.database().get();\n        }\n        if (mongoClientConfig.connectionString().isPresent()) {\n            String database = new ConnectionString(mongoClientConfig.connectionString().get()).getDatabase();\n            if (database != null) {\n                return database;\n            }\n        }\n\n        if (mongoEntity == null) {\n            throw new IllegalArgumentException(\n                    \"The database was not configured for the default Mongo Client via 'quarkus.mongodb.database' \"\n                            + \"or the connection string\");\n        }\n        if (mongoEntity.clientName().isEmpty()) {\n            throw new IllegalArgumentException(\"The database attribute was not set for the @MongoEntity annotation \"\n                    + \"and the database was not configured for the default Mongo Client via 'quarkus.mongodb.database' \"\n                    + \"or the connection string\");\n        }\n        throw new IllegalArgumentException(String.format(\n                \"The database attribute was not set for the @MongoEntity annotation and the database was not configured \"\n                        + \"for the named Mongo Client via 'quarkus.mongodb.%s.database' or the connection string\",\n                mongoEntity.clientName()));\n    }\n\n    public static Optional<String> getDatabaseNameFromResolver() {\n        return Optional.of(Arc.container().select(MongoDatabaseResolver.class))\n                .filter(Predicate.not(InjectableInstance::isUnsatisfied))\n                .map(InjectableInstance::get)","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/BeanUtils.java#L48-L84","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (application.properties)\nquarkus.mongodb.connection-string=mongodb://localhost:27017\n\n// after\nquarkus.mongodb.connection-string=mongodb://localhost:27017\nquarkus.mongodb.database=mydb","handlingStrategy":"validation","validationCode":"if (config.getOptionalValue(\"quarkus.mongodb.database\", String.class).isEmpty()\n        && config.getOptionalValue(\"quarkus.mongodb.connection-string\", String.class)\n              .map(cs -> !new ConnectionString(cs).getDatabase().isEmpty()).orElse(false) == false) {\n    throw new IllegalStateException(\"Configure quarkus.mongodb.database or a connection string with /database\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    repository.listAll();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"database was not configured\")) {\n        log.error(\"MongoDB database not configured: set quarkus.mongodb.database\", e);\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["mongodb","panache","configuration","quarkus"],"backgroundTag":"missing-config-property","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}