我在Mongo数据库中有2个集合,我想将它们与MongoRepository链接
集合1:C1 {“_ id”:ObjectId(“5a46864b8bf19446009fd0a5”),“name”:“test1”“c2_link”:ObjectId(“5a46864b8bf19446009fd0a7”)},{“_ id”:ObjectId(“5a46864b8bf19446009fd0a6”),“name “:”test2“”c2_link“:ObjectId(”5a46864b8bf19446009fd0a7“)}集合2:C2 {”_ id“:ObjectId(”5a46864b8bf19446009fd0a7“),”name“:”test3“}
@Document(collection="C1")
public class C1 {
@Id
private String _id;
private String name;
//Constructor and Getters and setters
}
@Document(collection="C2")
public class C2 {
@Id
private String _id;
private String name;
private List<C2> c1_list;
//Constructor and Getters and setters
}
但是c1Repository.findall()返回:
{“_ id”:ObjectId(“5a46864b8bf19446009fd0a7”),“name”:“test2”,c1_list:null}