简体   繁体   English

neo4j密码加入2个节点合并

[英]neo4j cypher joining 2 nodes merge

I have 2 node tags: User, Tag. 我有2个节点标签:用户,标签。

Lets say that I have a user node that exists. 可以说我有一个存在的用户节点。

Is it possible to match that node, and then if the tag exists merge between them, and if the tag doesn't exist create the tag. 是否可以匹配该节点,然后如果标签存在,则在它们之间合并,如果标签不存在,则创建标签。

I tryed: 我尝试过:

MATCH (n:User {name: "user"}) MERGE (n)-[r:follow]->(tag:Tag {name: "notexist")

In the above example it creates the node "notexist" and the relationship. 在上面的示例中,它创建了节点“ notexist”和该关系。 But if I have a node that is named "notexist" it doesn't merge, instead it creates another tag named "notexist" 但是,如果我有一个名为“ notexist”的节点,它不会合并,而是会创建另一个名为“ notexist”的标签

thank you 谢谢

Lee,

Here's how to do this. 这是这样做的方法。

MATCH(n:User {name: 'user'})
WITH n
MERGE (t:Tag {name: 'notexist'})
WITH n, t
MERGE (n)-[r:follow]->(t);

Grace and peace, 恩典与和平

Jim 吉姆

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

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