简体   繁体   中英

PHP Neo4j NOT relationship query is not working

I am trying to execute the NOT relation query but the condition just does not apply. What am I doing wrong here?

The query I tried:

MATCH (blog:Blog), (user:User{id:3})-[:FOLLOWS]->(otherUser:User) 
WHERE NOT ((otherUser)-[:OWNS]->(blog))
RETURN blog

Query should return - all blogs that my friends do not own. My id is 3. So all the blogs owned by other users should be returned.

You span up a cross product between all blogs and all friends of the user.

But the condition is only checked for each pair.

You probably want this:

MATCH (user:User{id:3})
MATCH (blog:Blog)
WHERE NOT ((user)-[:FOLLOWS]->()-[:OWNS]->(blog))
RETURN blog

or this

MATCH (user:User{id:3})-[:FOLLOWS]->(otherUser:User) 
WITH collect(otherUser) as friends
MATCH (otherUser)-[:OWNS]->(blog:Blog)
WHERE NOT otherUser IN friends
RETURN blog

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