问题描述
对于以下查询:
START n=node(1)
MATCH (n)-[:KNOWS]->(k), (n)-[:LOVES]->(l)
WITH collect(k) + collect(l) as friends, n
FOREACH(f in friends : create unique (n)-[:FRIEND]->(f))
(数据与console.neo4j.org相同)我希望朋友是Morpheus和Trinity,所以从Neo到Morpheus和Neo到Trinity建立了新的FRIEND关系.但是,在执行查询时,只会创建一个关系(Neo-[:FRIEND]-> Morpheus).再次执行查询,并创建另一个关系(Neo-[:FRIEND]-> Trinity)
(Data is as on console.neo4j.org)I expect that friends are Morpheus and Trinity so a new FRIEND relation is created from Neo to Morpheus and Neo to Trinity.However, on executing the query, there is only one relation created (Neo-[:FRIEND]->Morpheus).Execute the query again and the other relation is created (Neo-[:FRIEND]->Trinity)
那是为什么? (使用Neo4j 1.8.2)
Why is that? (Using Neo4j 1.8.2)
推荐答案
我今天在变更日志中注意到这是一个错误,并且已在最新的1.9.M05版本中修复. Fixes #489 - CREATE UNIQUE does not work as expected inside FOREACH
i noticed today in the changelog that this was a bug and has been fixed in the newest 1.9.M05 version. Fixes #489 - CREATE UNIQUE does not work as expected inside FOREACH
这篇关于创建唯一时,Cypher foreach似乎不会遍历集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!