首页 > 解决方案 > 找不到类型类调试错误的 PersistentEntity

问题描述

我有以下代码尝试将文档对象插入 mongoDB。

        return reactiveMongoTemplate.insert(document)
                .doOnSuccess(filler -> System.out.println(filler))
                .onErrorResume(e -> {
                    String message = format("Error saving %s", e.getMessage());
                    log.error(message, e);
                    throw new PersistenceException(message, e);
                })
                .block();

当我调试时,我收到一个错误,上面写着 org.springframework.data.mapping.MappingException: Couldn't find PersistentEntity for type class org.bson.Document!

这被标识为在返回的第一行。有谁知道为什么会这样?

标签: javaspringmongodb

解决方案


这似乎是一个错误(至少它类似于这个报告的问题)。无论如何,似乎包含集合名称作为第二个参数插入方法确实可以正常工作:

return reactiveMongoTemplate.insert(document, "documentCollection")
  // ...

这对我有用。


推荐阅读