1

I am hoping someone can help me figure out why this bulk update to relationship properties is not working from the given dataset. The id value in the dataset is the neo4j ID of the relationship. tq, rpc and weight are the properties on it.

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);
});

I get no errors, it falls into success function, but no properties actually update.

1 Answer 1

1

When using the official neo4j Javascript driver, you should use the neo4j.int() function to wrap an integer value being passed via a parameter, to work around the fact that Javascript does not support 64-bit integers (whereas that is what neo4j uses). By default, the Javascript driver converts integers in parameters to floats.

A float will not be considered equal to an equivalent integer.

Try changing your array, like this:

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)}
];
1
  • Wow, great answer. Worked perfectly! Thank you :) Apr 18, 2019 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.