我想使用 foreach 创建节点和关系。为每个 m 创建两个节点 p,其中 m [Knows]:
start n=node(1)
foreach(i in range(1,2):
create (m{id:i})
foreach(j in range(1,2):
create (p{name:i,id:j}),
(m)-[:knows]->(p)
)
);
没有语法错误,但它创建的节点比我预期的要多。以下是创建的所有节点:
==> | Node[27]{id:1} |
==> | Node[28]{name:1,id:1} |
==> | Node[29]{name:1,id:2} |
==> | Node[30]{name:1,id:1} |
==> | Node[31]{} |
==> | Node[32]{name:1,id:2} |
==> | Node[33]{} |
==> | Node[34]{id:2} |
==> | Node[35]{name:2,id:1} |
==> | Node[36]{name:2,id:2} |
==> | Node[37]{name:2,id:1} |
==> | Node[38]{} |
==> | Node[39]{name:2,id:2} |
==> | Node[40]{} |
这些命令如何创建节点(30-33)和节点(37-40)?它们之间的关系是:
(31)-[:knows]->(30)
(33)-[:knows]->(32)
(38)-[:knows]->(37)
(40)-[:knows]->(39)
请帮帮我。太谢谢了。