我有 photos_comments 收藏:
{
"_id" : ObjectId(""),
"photo_id" : ObjectId(""),
"content" : "Comment 1",
"is_approved" : "1",
"user" : {
"user_id" : ObjectId(""),
"name" : "",
"avatar" : ".jpg"
},
"likes" : [
{
"user_id" : ObjectId("")
}
],
"like_count" : 1,
"reply_count" : 5,
"replies" : [
{
"reply_id" : ObjectId(""),
"content" : "Reply 1",
"is_approved" : "1",
"user" : {
"user_id" : ObjectId(""),
"name" : "",
"avatar" : ".jpg"
},
"likes" : [
{
"user_id" : ObjectId("")
}
],
"like_count" : 1
},
]
}
我使用 $in 检查当前用户是否喜欢回复评论:
$collection->aggregate(
[
[
'$match' => [
'_id' => new ObjectId($comment_id)
]
],
[
'$project' => [
'replies.reply_id' => 1,
'replies.like_count' => 1,
'replies.content' => 1,
'replies.is_liked' => ['$in' => [['user_id' => $user_id], '$replies.likes']],
'replies.user' => 1,
'replies.created_at' => 1
]
],
['$sort' => ["replies.reply_id" => 1]],
['$limit' => 5]
]);
但是replies.is_liked 总是返回false,尽管它存在于replies 数组嵌入的likes 数组中的user_id。
如何解决?谢谢!
看起来您的帖子主要是代码;请添加更多细节。
慕尼黑的夜晚无繁华