简体   繁体   中英

Match biderectional relationships in Neo4j Cypher

I have the following domain model:

Author - creates posts and can reply to comments
Guest/Reader - can leave comments

I want to find authors that didn't reply to comments of a specific user.

I tried the following query, but it doesn't work.

MATCH (author:Author),(reader) WHERE NOT (author:Account)-[:REPLIED_TO_COMMENT]-[:LEFT_COMMENT]-(reader) RETURN DISTINCT author

Please help to create a valid query.

If I got your question correctly the query should be defined as follows:

MATCH (author:Author),(reader:Reader {email:'specific@user.email'}) 
WHERE NOT (author)-[:REPLIED_TO_COMMENT]->(:ReaderComment)<-[:LEFT_COMMENT]-(reader)
RETURN DISTINCT author

Explanation of the query:

  1. MATCH (author:Author),(reader:Reader {email:'specific@user.email'}) - as you stated you need to query a specifc reader, therefore we are filtering readers by email (just for example), also we are defining author and reader "variables" to use later.
  2. WHERE NOT (author)-[:REPLIED_TO_COMMENT]->(:ReaderComment)<-[:LEFT_COMMENT]-(reader) AND - you've missed the comment Node Type. We can read this as follows Where an author didn't reply to any comments left by a specific reader

I hope this will match your requirements.

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