如何将节点属性设置为递增数字? [英] How to set node properties as incrementing numbers?
本文介绍了如何将节点属性设置为递增数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
id()
节点)。根据此答案,我可以return the increment of number along with the nodes:
MATCH (n) where n.gid="Tt"
WITH collect(n) as nodes
WITH apoc.coll.zip(nodes, range(0, size(nodes))) as pairs
UNWIND pairs as pair
RETURN pair[0].gid as gid, pair[1] as rowNumber
╒═════╤═══════════╕
│"gid"│"rowNumber"│
╞═════╪═══════════╡
│"Tt" │0 │
├─────┼───────────┤
│"Tt" │1 │
├─────┼───────────┤
│"Tt" │2 │
├─────┼───────────┤
│"Tt" │3 │
├─────┼───────────┤
但是,如果我将最后一行更改为
SET pair[0].id=pair[1]
然后我收到此错误:
Invalid input '[': expected ":" (line 5, column 9 (offset: 145))
"set pair[0].id=pair[1]"
^
有没有办法将节点的ID设置为递增数字?当然,Cypher将pair[0]
单独理解为节点;如果它在RETURN
子句中,则pair[0].id
仍然有效。为什么此语法在SET
中不起作用?
推荐答案
应该可以,将pair[0]
包装在()
中,告诉Neo4j它是一个节点:
MATCH (n) where n.gid="Tt"
WITH collect(n) as nodes
WITH apoc.coll.zip(nodes, range(0, size(nodes))) as pairs
UNWIND pairs as pair
SET (pair[0]).id = pair[1]
这篇关于如何将节点属性设置为递增数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文