简体   繁体   English

如何在两个节点之间的neo4j中创建关系?

[英]How do I create a relationship in neo4j between two nodes?

I know the question above is a bit vague, but if I was more specific it wouldn't have fit in the title space. 我知道上面的问题有点模糊,但如果我更具体,它就不适合标题空间。 I am a bit unfamiliar with neo4j and cypher, but I think I am getting it. 我对neo4j和cypher有点不熟悉,但我想我得到了它。 The problem I am having though is with two nodes I am trying to relate using a (:WRITTEN_BY) relation. 我遇到的问题是我尝试使用(:WRITTEN_BY)关系关联的两个节点。 The syntax I am using is this: 我使用的语法是这样的:

MATCH (d:Document), (p:Person) 
WHERE d.DocID = 'P-267-b' AND  p.PersonName = 'Billy Bob' 
CREATE (d)-[r:SIGNED_BY]->(p)
RETURN r

This doesn't cause any errors, but it doesn't return anything either. 这不会导致任何错误,但它也不会返回任何错误。 I already created the nodes that are used here, but when I use this code, no relation is actually created as far as I can tell. 我已经创建了这里使用的节点,但是当我使用这个代码时,就我所知,实际上并没有创建任何关系。 What am I doing wrong here? 我在这做错了什么? I have seen similar problems, but the solutions that were suggested didn't work for mine. 我已经看到了类似的问题,但建议的解决方案对我来说不起作用。

Try this if nodes are created then this query should work. 如果创建了节点,请尝试此操作,然后此查询应该有效 Be careful with property names and label names because Cypher query is case sensitive . 请注意属性名称和标签名称,因为Cypher查询区分大小写 The first statement matches the nodes and second statement creates relation between document and person nodes. 第一个语句匹配节点,第二个语句创建文档和人员节点之间的关系。

MATCH (d:Document {docID:"P-267-b"}), (p:Person {personName:"Billy Bob"}) 
CREATE (d)-[r:SIGNED_BY]->(p)
RETURN r

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

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