How to get if the user has liked a post when the likes are in different collection and are parent referenced to user and the post in mongoose?

Viewed 16

I have a 'posts' collection and users can like posts. I have created another collection for 'Likes' where each like is a separate document referencing to the post and the user (parent referencing).

Now, when the user requests for the post, I want to add to the response if the user has already liked the post so that I can highlight the liked button on the user-interface.

here is my Post model: Post Model. And here is my Like model: Like Model

0 Answers
Related