How to insert an array of objects (array-paste) into neo4j with bolt protocol (javascript)

1.Send http message with an array of objects to the server

[{id:1, title: 'one'}, {id:2, title:'two'}] 

2. Receive a message on the server and attach it to neo4j with a 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. Configuring 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 
+6
source share
1 answer

In step 3, you can pass all list input (from step 1) as a parameter. (However, if the input list is very long, you should divide it into smaller batches - say, 10,000 items each.)

For instance:

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

All Articles