在mongo存储库中过滤对象的DBRef数组将返回空

时间:2019-05-09 12:55:45

标签: mongodb spring-boot spring-mongodb mongorepository

这里我正在使用MongoRepository,我需要查询DBRef对象的列表,该列表包含内部对象数组中的某些ID。

文档结构:

{
"_id" : ObjectId("5ccfe299902bb32f5a194ed7"),
"email" : "JohnDoe@gmail.com",
"name" : "JohnDoe",
    DBRef("webinarSignups", ObjectId("5ccfe298902bb32f5a194ed6"))
],
"_class" : "io.sample.persistencelayer.domain.User",
"bookletSignups" : [
    DBRef("bookletSignups", ObjectId("5ccfe2a9902bb32f5a194ed8"))
],
"eventSignups" : [
    DBRef("eventSignups", ObjectId("5ccfe2b6902bb32f5a194ed9"))
],
"infoSignups" : [
    DBRef("infoSignups", ObjectId("5ccfe2c2902bb32f5a194eda"))
 ]
}

存储库:

@RepositoryRestResource(collectionResourceRel = "users",path = "users")
public interface UserRepository extends MongoRepository<User,String> {

@org.springframework.data.mongodb.repository.Query(value = "{ 'webinarSignups': { $elemMatch: { 'webinarId' : ?0 } }}")
List<User> findByWebinarId(String id);

}

用户模型类:

@Data
@Document(collection = "user")
public class User implements Serializable {

@Id
private String id;
private String email;
private String name;
@Field("bookletSignups")
@DBRef
private List<BookletSignUp> bookletSignups;
@Field("eventSignups")
@DBRef
private List<EventSignUp> eventSignups;
@Field("infoSignups")
@DBRef
private List<InfoSignUp> infoSignups;
@Field("webinarSignups")
@DBRef
private List<WebinarSignUp> webinarSignups;
}

0 个答案:

没有答案