问题
1.Send an http post with objects array to server
[{id:1, title: ‘one’},
{id:2, title:’two’}]
2.Receive post on server and bulk insert into neo4j with bolt
let data = req.body;
//set up bolt
let db = require('neo4j-driver').v1;
let driver = db.driver('bolt://localhost', db.auth.basic('neo4j', ’neo4j’));
let session = driver.session();
3. Set up statements for execution
// start transaction
for(var i=0; i>data.length; i++) {
//add CREATE statements to bolt session ???
"CREATE (r:Record {id:1, title:'one'})"
"CREATE (r:Record {id:2, title:'two'})"
...
}
//execute session.run(???);
//stop transaction
回答1:
In step 3, you can pass your entire input list
(from step 1) as a parameter. (However, if the input list is very long, you should split it into smaller batches -- say of 10,000 items each.)
For example:
session
.run(
"UNWIND {list} AS i CREATE (:Record {id: i.id, title: i.title})",
{ list: list })
.then(function(result){
// Use the result ...
session.close();
})
.catch(function(error) {
console.log(error);
});
来源:https://stackoverflow.com/questions/37828785/how-to-insert-an-array-of-objects-bulk-insert-into-neo4j-with-bolt-protocol-j