{"record":{"id":"e985ce605a00951f","repo":"quarkusio/quarkus","slug":"the-database-attribute-was-not-set-for-the-mongoe","errorCode":null,"errorMessage":"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","messagePattern":"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","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":71,"sourceCode":"        }\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)\n                .map(MongoDatabaseResolver::resolve)\n                .filter(Predicate.not(String::isBlank));\n    }\n\n    private static <T> T firstInstanceWithoutQualifier(Iterable<InstanceHandle<T>> handles,","sourceCodeStart":53,"sourceCodeEnd":89,"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#L53-L89","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set the database on the annotation: @MongoEntity(database=\"mydb\")","Set 'quarkus.mongodb.database=mydb' in application.properties","Embed the database in the default connection string: quarkus.mongodb.connection-string=mongodb://host:27017/mydb"],"exampleFix":"// before\n@MongoEntity(clientName = \"default\")\npublic class Person extends PanacheMongoEntity {}\n\n// after\n@MongoEntity(clientName = \"default\", database = \"mydb\")\npublic class Person extends PanacheMongoEntity {}","handlingStrategy":"validation","validationCode":"MongoEntity anno = MyEntity.class.getAnnotation(MongoEntity.class);\nif (anno == null || anno.database().isEmpty()) {\n    throw new IllegalStateException(\"@MongoEntity(database=...) must be set or quarkus.mongodb.database configured\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    entity.persist();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"@MongoEntity annotation\")) {\n        log.error(\"Set database on @MongoEntity or quarkus.mongodb.database\", e);\n    }\n    throw e;\n}","preventionTips":["Whenever you add @MongoEntity, always set the database attribute explicitly","Keep database config centralized in application.properties rather than annotation attributes so one place controls it","Cover every repository operation with an integration test against a configured dev-service database"],"tags":["mongodb","panache","configuration","mongoentity"],"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-12T22:17:10.623Z"}