I'm attempting to get all friend requests of a specific profile. The cypher query that I have is the following:
.run(
'MATCH (p:Profile {uuid: $profileUuid})' +
' OPTIONAL MATCH (p)-[friendRequests:FRIEND_REQUEST]->(u)' +
' OPTIONAL MATCH (e)<-[reverseFriendRequest:FRIEND_REQUEST]-(l)' +
' return friendRequests',
{
profileUuid,
})
Where profileUuid is the uuid of the profile that im attempting to retrieve all FRIEND_REQUEST relationships that are ongoing or incoming from/to it. But the above query is returning all FRIEND_REQUEST relationships for all nodes. Do I have to add a where somewhere? If yes isnt that what the first MATCH is supposed to be doing?
In the second OPTIONAL match, you should replace
(e)by(p). Since the(l)and(e)are unbound, that's why you get everything.An alternative would be something like this:
or