Neo4j Cypher Relationships批量更新属性

时间:2019-04-17 21:42:06

标签: neo4j cypher neo4j-driver neo4j-javascript

我希望有人能帮我弄清楚为什么对给定数据集的这种对关系属性的批量更新无法正常工作。数据集中的id值是关系的neo4j ID。 tqrpcweight是其属性。

var batchUpdate = [{"id":281,"tq":8,"rpc":2.4,"weight":84},{"id":283,"tq":5,"rpc":1.25,"weight":10},
{"id":286,"tq":4,"rpc":3.2,"weight":5}];

var nQuery = WITH {batchUpdate} AS stats UNWIND stats AS s MATCH ()-[k:BELONGS_TO]-() WHERE id(k)=s.id SET k.weight=s.weight, k.rpc=s.rpc, k.tq=s.tq;

session
.run(nQuery,{batchUpdate:batchUpdate})
.then(function (result) {
console.log('updated');
})
.catch(function (error) {
console.log('neo4j stats update error ' + error);
});

我没有收到任何错误,它属于成功函数,但实际上没有属性更新。

1 个答案:

答案 0 :(得分:1)

使用正式的neo4j Javascript驱动程序时,应使用neo4j.int()函数来包装通过参数传递的整数值,以解决Javascript不支持64位整数的事实(而那是neo4j使用什么)。默认情况下,Javascript驱动程序将参数中的整数转换为浮点数。

浮点数将不被视为等于等效整数。

尝试更改数组,如下所示:

var neo4j = require('neo4j-driver').v1;

...

var batchUpdate = [
  {"id":neo4j.int(281),"tq":neo4j.int(8),"rpc":2.4, "weight":neo4j.int(84)},
  {"id":neo4j.int(283),"tq":neo4j.int(5),"rpc":1.25,"weight":neo4j.int(10)},
  {"id":neo4j.int(286),"tq":neo4j.int(4),"rpc":3.2, "weight":neo4j.int(5)}
];
相关问题