如何使用bolt协议(javascript)将对象数组(bulk-insert)插入到neo4j中 [英] How to insert an array of objects (bulk-insert) into neo4j with bolt protocol (javascript)

查看:163
本文介绍了如何使用bolt协议(javascript)将对象数组(bulk-insert)插入到neo4j中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

1.Send an http post with objects array to server

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

2.Receive post在服务器和批量插入到neo4j与螺栓

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。设置执行语句

    // 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


推荐答案

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

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.)

例如:

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

这篇关于如何使用bolt协议(javascript)将对象数组(bulk-insert)插入到neo4j中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆