[英]Match biderectional relationships in Neo4j Cypher
I have the following domain model:我有以下域 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:查询说明:
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. MATCH (author:Author),(reader:Reader {email:'specific@user.email'})
- 正如您所说,您需要查询特定的阅读器,因此我们通过 email 过滤读者(仅作为示例),我们也是正在定义author and reader
“变量”以供以后使用。WHERE NOT (author)-[:REPLIED_TO_COMMENT]->(:ReaderComment)<-[:LEFT_COMMENT]-(reader) AND
- you've missed the comment Node Type. WHERE NOT (author)-[:REPLIED_TO_COMMENT]->(:ReaderComment)<-[:LEFT_COMMENT]-(reader) AND
- 您错过了评论节点类型。 We can read this as follows Where an author didn't reply to any comments left by a specific readerI hope this will match your requirements.我希望这将符合您的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.