1
votes

I'm trying to get the nodes that are not related to a node and return them. For example, there is an event node that has pictures, I want to show the user only the pictures that he hasn't seen.

  1. I'm matching the event with pictures relation
  2. Match the user and the relation to pictures of that event that he has seen
  3. Where I'm having problems is how to query the difference between these two matches so I will have the images that have no relation to the user.

    MATCH photo=(i)-[r:EVENT_IMAGES]-(e{uuid:'ed3f4785-fc58-4d78-9ae1-ae738814a34a'}) MATCH user=(u{uuid:'4f731ba1-b15d-4a3f-85bd-446057c84cbc'})
    RETURN photo, user

1

1 Answers

2
votes

You can use a WHERE NOT clause with a pattern to filter out matches for a given pattern. For example:

MATCH (p:Photo)<-[r:EVENT_IMAGES]-(e:Event {uuid:'ed3f4785-fc58-4d78-9ae1-ae738814a34a'}) 
MATCH (u:User {uuid:'4f731ba1-b15d-4a3f-85bd-446057c84cbc'})
WITH p, u WHERE NOT (u)-[:VIEWED]->(p)
RETURN p, u