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"
}
]
}
私は、要素を見つけるためにJavaコードの下に書かれています。
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){
}
ヌルブロックが実行されていないため、実行が終了します。私が書いた質問が正しいかどうかを知る必要があります。