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

杀马特。学长 韩版系。学妹 提交于 2019-12-07 02:05:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!