Let consider this collection of posts. Each post has an array of comments and each comments has an array on string, with the key 'likes', which indicates the users who like the comment.
{
_id: 000
created_at:
user_id:
comments: [{
_id: 111
created_at:
likes: [user_id1 , user_id2 , user_id3]
},
{
_id: 222
created_at:
likes: [user_id1]
},]
}
How can I check, with mongoose, if a user has liked a comment with a given id?
I think that this query may be the thing you're looking for...
{
comments: {
$elemMatch: {
_id: 111,
likes: user_id1
}
}
}
Hope it helps you