I just got started on Neo & tried to look for prior questions on this topic. I need help to rename one of the property keys.
我刚刚开始研究Neo,并试图寻找关于这个话题的先前问题。我需要人帮我重命名其中一把钥匙。
I created the following node:
我创建了以下节点:
CREATE (Commerce:Category {title:' Commerce', Property:'Category', Owner:'Magic Pie', Manager:'Simple Simon'})
Now want to rename title to name. Is there a way to do it? I don't want to delete the node as there are 100's of nodes with the property "title".
现在想将标题重命名为名称。有办法吗?我不想删除节点,因为有100个节点具有属性“title”。
更多回答
优秀答案推荐
Yes, you want to SET
a new property name
with the value of the old property title
. And then REMOVE
the old property title
. Something like this...
是的,您希望使用旧属性标题的值设置新的属性名称。然后删除旧的产权。就像这样……
MATCH (c:Category)
WHERE c.name IS NULL
SET c.name = c.title
REMOVE c.title
If you have MANY nodes, it is advisable to perform the operation in smaller batches. Here is an example of limiting the operation to 10k at a time.
如果您有许多节点,建议以较小的批次执行该操作。下面是一个将操作限制为一次10K的示例。
MATCH (c:Category)
WHERE c.name IS NULL
WITH c
LIMIT 10000
SET c.name = c.title
REMOVE c.title
another solution would be using APOC functions:
另一种解决方案是使用APOC函数:
MATCH (n) WHERE ID(n) = 1234
WITH *, collect(n) AS nodes // nodes must be converted into a collection first
CALL apoc.refactor.rename.nodeProperty("oldKey ", "newKey", nodes)
// rename doesn't work if the key has strings ^ postfixed in it
YIELD batches, total, timeTaken, committedOperations
RETURN *
in the case you accidentially added strings at the end (it's possible during create) the property cannot be accessed via:
如果您意外地在末尾添加了字符串(可能在创建过程中),则无法通过以下方式访问该属性:
SET n.newKey = n.oldKey
REMOVE n.oldKey
then you must use:
然后,您必须使用:
SET n.newKey = n.`oldKey `
REMOVE n.`oldKey `
this works
这很管用
And also, just for addition, you can use:
此外,仅用于添加,您还可以使用:
SET c.name = c.title, c.title = null
instead of
而不是
SET c.name = c.title
REMOVE c.title
People have different views and usages on queries, just use whatever suits you.
人们对查询有不同的看法和用法,只要适合你就行。
更多回答
Fascinating fact, but when you pass a query to Neo4j, it loads everything into memory before it performs the operation. This is why the Neo4j browser melts down for a long time when you run monster queries. There is a cypher shell program
you can get that apparently remedies that, but as mentioned above, it's due to lack of batching.
这是一个有趣的事实,但当您向Neo4j传递查询时,它会在执行操作之前将所有内容加载到内存中。这就是为什么当你运行怪物查询时,Neo4j浏览器会长时间崩溃。有一个密码外壳程序,你可以得到明显的补救措施,但如上所述,这是由于缺乏批处理。
我是一名优秀的程序员,十分优秀!