如何使用bolt协议(javascript)将对象数组(bulk-insert)插入到neo4j中

时间:2016-06-15 07:28:19

标签: javascript neo4j bulkinsert

1.发送带有对象数组的http帖子到服务器

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

2.在服务器上接收帖子并使用bolt

批量插入neo4j
    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。设置执行语句

    // 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 个答案:

答案 0 :(得分:0)

在步骤3中,您可以将整个输入list(来自步骤1)作为参数传递。 (但是,如果输入列表很长,则应将其拆分为较小的批次 - 例如每个10,000个项目。)

例如:

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