简体   繁体   English

在 Neo4j 中,如何在一个节点与其他节点的集合之间创建关系?

[英]In Neo4j how can I create relationships between one node an a collection of other nodes?

I have a graph containing some nodes with :SubSystem labels.我有一个图表,其中包含一些带有:SubSystem标签的节点。 I want to add a new node with a :Document label and create relationships with each of the existing :SubSystem nodes.我想添加一个带有:Document label 的新节点,并与每个现有的:SubSystem SubSystem 节点创建关系。

When I execute this statement:当我执行此语句时:

MATCH (s:SubSystem)
CREATE (d:Document {title:'New Document'})
CREATE (d)-[:DEPICTS]->(s);

I was surprised when Neo4j created a new :Document node for each :SubSystem .当 Neo4j 为每个:SubSystem SubSystem 创建一个新的:Document节点时,我感到很惊讶。 I have 12 sub-systems, so I ended up with 12 new documents each related to one sub-system.我有 12 个子系统,所以我最终得到了 12 个新文档,每个文档都与一个子系统相关。 I would have expected this behavior had I written:如果我写的话,我会预料到这种行为:

MATCH (s:SubSystem)
CREATE (:Document {title:'New Document'})-[:DEPICTS]->(s);

But I was expecting that separating the CREATE clauses would create 1 document then create relationships between that document and each of the sub-systems.但我期望分离CREATE子句会创建 1 个文档,然后在该文档和每个子系统之间创建关系。

Can someone explain why this doesn't work as I was expecting.有人可以解释为什么这不能像我预期的那样工作。

EDIT:编辑:

I found a solution.我找到了解决方案。 This statement does what I wanted, but I still think my original attempt should have worked.这个声明做了我想要的,但我仍然认为我最初的尝试应该奏效。

CREATE (d:Document {title:'New Document'})
WITH d MATCH (s:SubSystem) CREATE (d)-[:DEPICTS]->(s);

A MATCH clause generates one or more result rows (or aborts the query if no results are found). MATCH子句生成一个或多个结果行(如果未找到结果,则中止查询)。 A subsequent read/write clause would be executed once per row .随后的读/写子句将每行执行一次。 Rearranging the order of the clauses, as you did, is one way to work around that (when possible).正如您所做的那样,重新排列子句的顺序是解决该问题的一种方法(如果可能)。

暂无
暂无

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

相关问题 如何使用 Spring 数据 Neo4j 创建一个与现有节点具有新关系的节点 - How can I use Spring Data Neo4j to create a Node with new Relationships to existing Nodes 如何使用 php 和 neo4j 在节点之间创建关系 - how can i create relationships between nodes using php and neo4j 如何显示 neo4j 中的所有节点和两个节点之间的关系? - How can i display the all nodes and relationships between two nodes in neo4j? 如何在Neo4j中对两个节点之间的关系数量创建约束 - How do I create a constraint on the number of relationships between two nodes in Neo4j 如何使用neo4j cypher查询创建按关系数量划分的节点直方图? - How can I use neo4j cypher query to create a histogram of nodes bucketed by number of relationships? 如何从取决于节点类型的 csv 在 neo4j/Cypher 中创建关系? - How can I create relationships in neo4j/Cypher from a csv that depend on the type of nodes? 在Neo4j中,可以找到其关系是另一个节点关系的超集的所有节点吗? - In Neo4j, can one find all nodes whose relationships are a superset of another node's relationships? 在Neo4j中创建后续节点之间的关系(日期属性) - Create Relationships between Consequent Nodes (on date attribute) in Neo4j 是否可以在Neo4j中的节点之间创建未指定的类型关系 - Is it possible to create unspecified type relationships between nodes in Neo4j 如何有效地在Neo4j中创建独特的关系? - How can I efficiently create unique relationships in Neo4j?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM