Json spring boot mongodb@dbref级联不工作

Json spring boot mongodb@dbref级联不工作,json,spring-boot,spring-mongodb,Json,Spring Boot,Spring Mongodb,我正在为引用对象上的Spring Boot MongoDB级联操作而挣扎。下面是MongoDB文档模式类 ==Post @Getter @Setter @Document(collection="Post") // (1) public class Post { @Id private String _id; @Indexed(unique = true) private Long id; private String title; p

我正在为引用对象上的Spring Boot MongoDB级联操作而挣扎。下面是MongoDB文档模式类

==Post

@Getter
@Setter
@Document(collection="Post") // (1)
public class Post {

    @Id
    private String _id;

    @Indexed(unique = true) 
    private Long id; 

    private String title;

    private String body;

    private Date createdDate;

    @DBRef(db = "User", lazy = true) 
    private User user;

    @DBRef(db = "Tag", lazy = true) 
    private Collection<Tag> tags;
==标签

@Getter
@Setter
@Document(collection="Tag")
public class Tag {

    @Id
    private String _id;

    @Indexed(unique = true)
    private Long mid;

    private String body;

    private Date createdDate;

    @DBRef(db = "User", lazy = true) 
    private User user;
}
但是@DBRef注释根本不起作用。它抛出以下异常

2019-03-01 14:54:10.411 ERROR 5756 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.mapping.MappingException: Cannot create a reference to an object with a NULL id.] with root cause

org.springframework.data.mapping.MappingException: Cannot create a reference to an object with a NULL id.
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:975) ~[spring-data-mongodb-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:597) ~[spring-data-mongodb-2.1.4.RELEASE.jar:2.1.4.RELEASE]

将json文件导入MongoDB模式时,会显示上述错误。我在谷歌上找到了一些参考资料,上面说使用CascadingMongoEventListener类和用户定义的@CascadeSave注释生成新的事件源。但我认为还有另一种带有级联注释的解决方案。任何想法,请。

Mongo
不支持
文档之间的关系。由于此级联操作不支持spring中的数据mongo。你可以用两种方式来做

1) 制作您自己的级联处理程序(最好的方法是使用
spring事件
publisher),但也可以使用没有spring事件的自定义处理程序来完成。

2) 显式调用引用的DB进行操作。

看看哪一个是构建在Spring数据之上的框架,哪一个使级联、获取成为可能。。甚至使用DBRefs无法进行的查找

谢谢您的回复。然后我想知道如何将文档划分为模块文档(例如,$ref注释)。如果您有任何参考网站,请通知我。谢谢更新了我的答案,并共享了一个链接供参考。
2019-03-01 14:54:10.411 ERROR 5756 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.mapping.MappingException: Cannot create a reference to an object with a NULL id.] with root cause

org.springframework.data.mapping.MappingException: Cannot create a reference to an object with a NULL id.
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:975) ~[spring-data-mongodb-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:597) ~[spring-data-mongodb-2.1.4.RELEASE.jar:2.1.4.RELEASE]