[英]Querying for nodes with multiple relationships of the same type
I'm just starting to learn about Neo4J and I thought up a question I haven't seen an answer to in the reading I've been doing so far. 我才刚刚开始学习Neo4J,我想了一个问题,到目前为止我一直在阅读中没有看到答案。
I believe it's possible for a Node to be connected to another Node with the same relationship multiple times. 我相信一个节点有可能多次连接到具有相同关系的另一个节点。
Is it possible to return only the nodes where the number of Relationship edges meets some criteria? 是否可以仅返回关系边数满足某些条件的节点?
Example: 例:
Friend is a node. 朋友是一个节点。 Poked is a relationship.
戳是一种关系。
How would I query this so only Friend A is selected because it has poked the same friend more than once? 我将如何查询此消息,以便仅选择“朋友A”,因为它多次戳了同一个朋友?
If it matters; 如果重要的话; I'll be using Java and Spring's Data Graph module.
我将使用Java和Spring的Data Graph模块。
I'm assuming you want to use Cypher. 我假设您要使用Cypher。 Who wouldn't, right?
谁不会,对吗?
Cypher doesn't have the SQL equivalent of HAVING, so you will have to do a little bit in your host language. Cypher没有等效于HAVING的SQL,因此您将不得不使用宿主语言做一些事情。 The query would look something like this:
查询如下所示:
START friendA=node:person(name="Michael")
MATCH friendA-[:POKED]->friendB
RETURN friendB, count(*)
Now, with the resulting iterable of maps, exclude from the final result all maps where count(*) is different from what you want it to be. 现在,有了映射的结果可迭代性,从最终结果中排除count(*)与您想要的不同的所有映射。
Does this make sense? 这有意义吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.