Neo4j 创造独一无二 + 在哪里
Neo4j Create Unique + Where in
同时使用 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
我希望这个密码 "tag" 节点 "node1" 带有标签 "Tag1" 和 "Tag2".
你应该先匹配Tag
然后添加关系:
MATCH (node1) WHERE node1.name = "node1"
WITH node1
MATCH (node2:Tag) WHERE node2.name IN ["Tag1","Tag2"]
CREATE UNIQUE node1-[:is_tagged]->node2
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
同时使用 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
我希望这个密码 "tag" 节点 "node1" 带有标签 "Tag1" 和 "Tag2".
你应该先匹配Tag
然后添加关系:
MATCH (node1) WHERE node1.name = "node1"
WITH node1
MATCH (node2:Tag) WHERE node2.name IN ["Tag1","Tag2"]
CREATE UNIQUE node1-[:is_tagged]->node2
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