Lomo
Lomo

Reputation: 89

Only show nodes that have a specific properties in relationship

I'm new to neo4j and im struggling with the task to build a simple filter.

I played around and found the in operator but it only list me every "Person" where atleast one match is found. I want to only list "Person" that have all the properties included.

MATCH (p:Person)-[l:LIKES]->(f:Food) WHERE f.name in ["Spaghetti","Cheese","Chicken","Eggs"]
RETURN p

Result: Show only "Person" that like "Spaghetti","Cheese","Chicken","Eggs", ...

Upvotes: 0

Views: 26

Answers (1)

InverseFalcon
InverseFalcon

Reputation: 30407

We have a knowledge base article on performing match intersection that should address this.

Applied to your case, here's one of the approaches you can use:

WITH ["Spaghetti","Cheese","Chicken","Eggs"] as foods
MATCH (p:Person)-[:LIKES]->(f:Food) 
WHERE f.name in foods
WITH p, foods, count(f) as foodsLiked
WHERE foodsLiked = size(foods)
RETURN p

Upvotes: 1

Related Questions