简体   繁体   English

neo4j cypher节点之间的多种关系

[英]neo4j cypher multi relationship between nodes

for example: 例如:

a-[r]->b, there are multi r between the two nodes, each r.userId is unique. a- [r] - > b,两个节点之间有多个r,每个r.userId都是唯一的。
(eg: a-[r:R {userId:"user1"}]->b, (a-[r:R{userId:"user2"}]->b, (例如:a- [r:R {userId:“user1”}] - > b,(a- [r:R {userId:“user2”}] - > b,
and the same for a-[r]->c 和 - [r] - > c相同

And the situation is a-[r]->b has a relationship: r.userId = amdin, but a-[r]->c doesn't have this relationship. 情况是a- [r] - > b有一个关系:r.userId = amdin,但a- [r] - > c没有这种关系。

how can i only return c. 我怎么能只返回c。

i try to create cypher: 我尝试创建密码:

"MATCH (a:SomeLabel)-[r:SomeR]->(any:SomeLabel) " “MATCH(a:SomeLabel) - [r:SomeR] - >(any:SomeLabel)”
"WHERE id(a)=0 AND r.userId <> \\"admin\\" " “WHERE id(a)= 0 AND r.userId <> \\”admin \\“”
"RETURN any"; “返回任何”;

but this will also return b ,because a->b has other relationship: r.userId=xxxx 但这也会返回b,因为a-> b有其他关系:r.userId = xxxx

how can i write the cypher to return nodes not inculde user.Id="admin"...... 如何编写cypher返回节点而不是inculde user.Id =“admin”......

If you not clearly understand what i say,please let me know....i need your help for this case..thanks 如果你不清楚我的意思,请告诉我....我需要你帮助这个案子..谢谢

I draw a picture below, multi relationship named sr but with different properties (userId is unique), and i want to find all nodes that related to node A, but not contains sr {userId:admin}, i add a red underline there. 我在下面画了一张图片,多个关系名为sr但具有不同的属性(userId是唯一的),我想找到与节点A相关但不包含sr {userId:admin}的所有节点,我在那里添加一个红色下划线。 So as in the picture, node B has the relationship sr {userId:admin}, so i only want to return node C, no node B 如图所示,节点B的关系为sr {userId:admin},所以我只想返回节点C,没有节点B

在此输入图像描述

For showing simple representations of graph problems, graphgists are really helpful as people can explore the data. 为了显示图形问题的简单表示,图形工作者非常有用,因为人们可以探索数据。 I've created one based on your description: http://gist.neo4j.org/?94ef056e41153b116e4f 我根据你的描述创建了一个: http//gist.neo4j.org/?94ef056e41153b116e4f

To your problem, you can collect all usernames involved in the relationships per pair of nodes and filter based on those: 对于您的问题,您可以收集每对节点的关系中涉及的所有用户名,并根据这些用户名进行过滤:

MATCH (a { name:'A' })-[r:sr]->b
WITH a,b, collect(r.name) AS usernames
WHERE NOT 'admin' IN usernames
RETURN a, b

Your question is pretty unclear. 你的问题很不清楚。 My interpretation is that you want to find nodes c that are not connected to a node a with a relationship of type R . 我的解释是,您希望找到未连接到具有类型R关系的节点a节点c

You basically want to do a negative match aka search for a pattern that does not exist. 你基本上想做一个负面的匹配,也就是搜索一个不存在的模式。 Negative patterns can be retrieved using a where not : 可以使用where not以下where not检索负模式:

MATCH (a:SomeLabel), (c:SomeLabel)
WHERE ID(a)=0 AND NOT (a)-[:R]->(c)
RETURN c

This returns a list of all SomeLabel nodes not being connected to a . 这将返回未连接到a的所有SomeLabel节点的列表。

See http://docs.neo4j.org/chunked/stable/query-where.html#query-where-patterns in the reference manual. 请参阅参考手册中的http://docs.neo4j.org/chunked/stable/query-where.html#query-where-patterns

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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