简体   繁体   中英

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", ...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM