提问人:geotheory 提问时间:10/27/2017 更新时间:10/27/2017 访问量:36
将批量节点与属性合并时的重复
Duplication when merging bulk nodes with attributes
问:
我无法从文档中看到如何将批量数据与属性合并。这里的示例使用 R,但解决方案将是 Cypher。我需要指定为唯一字段,以便在更改属性或添加新属性数据时不会重复节点。id
x = data.frame(id = 1:2, name = c('Kate','Charles'),
age = c(27,34), grp = c('A','B'), stringsAsFactors = F)
merge_df_with_graph = function(x, graph, query){
t = newTransaction(graph)
for (i in 1:nrow(x)) {
appendCypher(t, query, id = x$id[i], name = x$name[i],
age = x$age[i], grp = x$grp[i])
}
commit(t)
}
merge_df_with_graph(x, graph, "MERGE (n:User {id:{id}, name:{name}});")
n = getNodes(graph, 'MATCH (n) RETURN (n);')
length(n)
#> [1] 2
# when an attribute changes
x$name[2] = 'Charlie'
merge_df_with_graph(x, graph, "MERGE (n:User {id:{id}, name:{name}});")
n = getNodes(graph, 'MATCH (n) RETURN (n);')
length(n)
#> [1] 3
# when new attributes data is added
merge_df_with_graph(x, graph, "MERGE (n:User {id:{id}, name:{name}, age:{age}});")
n = getNodes(graph, 'MATCH (n) RETURN (n);')
length(n)
#> [1] 5
我是 neo4j 的新手,文档中的示例没有指定如何定义唯一键以外的属性。感谢您的帮助。
答:
2赞
Bruno Peres
10/27/2017
#1
您只能在其他属性中使用该属性,并在其他属性中使用该属性。id
MERGE
SET
MERGE (n:User {id:{id})
SET n.name = 'Kate'
# (...)
MERGE (n:User {id:{id})
SET n.name = 'Charlie'
SET n.age = 22
评论
1赞
geotheory
10/27/2017
对我来说,这翻译为 .太棒了,谢谢布鲁诺:)SET n.name = {name}
评论