Happy Monday. I hope you all are doing well.
Can anyone help me with a query and a scenario I am stuck with?
I am working on a social network platform where we have posts shared by users and each post can have likes.
MATCH (p:Post) OPTIONAL MATCH (:User)-[l:LIKED]->(p) WITH collect(DISTINCT p) as nodes, count(DISTINCT p) as count, count(l) as likes OPTIONAL MATCH (u2:User)-[:LIKED]->(p) WITH nodes, count, likes, u2 as likedBy LIMIT 1 UNWIND nodes as results RETURN results, count, likes, collect(likedBy) as likedByUsers``` In the query above, what I am trying to do is, fetch the **posts** along with the **users** who have liked the **post**. Here I am doing an **OPTIONAL MATCH** as there might be any **post** not liked by any **user**. In the first OPTIONAL MATCH, I am counting the total number of likes, and in the second OPTIONAL MATCH I am trying to get the list of users who have liked the post. Now here I only want to get a limited number of users i.e. 5 or 10 and implement the pagination later on. So when I add the LIMIT constraint, this limit is also applied to the posts as well. **Example:** Consider I have two posts A & B. Post A have 2 likes by different users. In this case: 1. When I try to limit it to 1 then I get only 1 post & 1 likedByUsers and when I increase this limit to let's say 3 I get 2 posts (which is fine) & two likedByUsers for post-A (which is also fine) but I am also getting 1 likedByUser for post B as well 2. Also according to this query I am getting likedByUsers list in the case of post B as well which shouldn't be the case as post B has no likes at this point in time. I am new to RedisGraph and I'll appreciate it if anyone can help me out. Thanks, Hammad Rasheed.