Neo4j创造独特+在哪里

时间:2015-01-22 12:04:46

标签: arrays neo4j duplicates cypher

同时使用Create Unique和WHERE IN的正确方法是什么? 或者更常见的是如何使用Create Unique从一系列道具中创建所需数量的路径?

我尝试过没有成功:

MATCH (node1) WHERE node1.name = "node1"
CREATE UNIQUE (node1)-[r:`is_tagged`]->(node2:Tag)
WHERE node2.name IN ["Tag1","Tag2"] 
RETURN r

我正在跳这个密码"标记"节点" node1"标签" Tag1"和" Tag2"。

2 个答案:

答案 0 :(得分:4)

create constraint on :Tag(name);

MATCH (node1:Document) WHERE node1.name = "node1"
FOREACH (t in ["Tag1","Tag2"] |
 MERGE (node2:Tag {name:t})
 CREATE|MERGE (node1)-[:is_tagged]->(node2)
);

或放松

MATCH (node1:Document) WHERE node1.name = "node1"
UNWIND ["Tag1","Tag2"] as t
MERGE (node2:Tag {name:t})
CREATE|MERGE (node1)-[r:is_tagged]->(node2)
RETURN r

答案 1 :(得分:1)

您应首先匹配Tag,然后添加关系:

MATCH (node1) WHERE node1.name = "node1"
WITH node1
MATCH (node2:Tag) WHERE node2.name IN ["Tag1","Tag2"]
CREATE UNIQUE node1-[:is_tagged]->node2