0
mongo DB에서 중첩 배열의 요소를 찾을 수 없습니다. mongo java 드라이버를 사용하고 있습니다. 주석 문서 안에 임베디드 문서가 있습니다.봄의 중첩 배열에 대한 쿼리 조건을 지정하십시오.
내 동기는 전달 된 ID가 회신 문서 내에있는 upvotes 목록 내에서 사용 가능한지 확인하는 것입니다. 아래는 json 응답 목록입니다.
{
"_id" : ObjectId("59d3a5bf8cffc24e747b63ea"),
"_class" : "com.forum.api.domain.Comments",
"pageId" : "59d20dce5a7baa0d38643590",
"comment_data" : "densghgfhng",
"name" : "Karthe",
"upvotes" : [
"59ce67c55c942046a0931dde"
],
"downvotes" : [],
"totalUpvotes" : 1,
"totalDownvotes" : 0,
"created_by" : "[email protected]",
"created_date" : ISODate("2017-10-03T14:59:11.799Z"),
"last_modified_by" : "[email protected]",
"last_modified_date" : ISODate("2017-10-03T14:59:11.799Z"),
"replies" : [
{
"_id" : "vxfddsg",
"content" : "Commented by solludhana1",
"createdDate" : ISODate("2017-10-04T14:08:30.374Z"),
"upvotes" : [],
"downvotes" : [],
"userName" : "Karthe"
}
]
}
나는 요소를 찾기 위해 아래의 자바 코드를 작성했습니다.
Query query = new Query();
new Query(new Criteria().andOperator(
Criteria.where("_id").is("59d3a5bf8cffc24e747b63ea"),
Criteria.where("replies.id").is("vxfddsg").elemMatch(Criteria.where("replies.upvotes").in("1002"))));
Comments comments = mongoOps.findOne(query, Comments.class);
if(comments==null){
}
null 블록이 실행되지 않으면 실행이 끝납니다. 나는 내가 쓴 것이 옳은지 아닌지를 알아야한다.