neo4j, nodejs, session expire error, how to fix it?

蹲街弑〆低调 提交于 2020-01-17 12:40:07

问题


I was trying to use neo4j at backend. First I want to import csv to neo4j. (first tried to see how many lines csv file has) But having problem, the code is following

var neo4j = require('neo4j-driver').v1;
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));

function createGraphDataBase(csvfilepath) 
{
  var session = driver.session();
  return session
     .run( 'LOAD CSV FROM {csvfilepath} AS line RETURN count(*)', 
         {csvfilepath}
  )
  .then(result => {
     session.close();
     console.log(' %d lines in csv.file', result);
     return result;
  })
  .catch(error => {
    session.close();
    console.log(error);
    return error;
  });
}

the "csvfilepath" is the path of csv file, it is as follows.

'/Users/.../Documents/Project/.../test/spots.csv'; is there something wrong with giving path like this?

I am calling that function on other module as

 var api = require('./neo4j.js');    
 const csvFile = path.join(__dirname,csvFileName); 
 api.createGraphDataBase(csvFile);

I am having error as

Error: Connection was closed by server ....

I am new to these, please help!


回答1:


The URL that you specify in a LOAD CSV clause must be a legal URL.

As stated in this guide:

Make sure to use the right URLs esp. file URLs.+ On OSX and Unix use file:///path/to/data.csv, on Windows, please use file:c:/path/to/data.csv

In your case, csvfilepath needs to specify the file:/// protocol (since you seem to be running on OSX) for a local file. Based on your example, the value should be something like this:

'file:///Users/.../Documents/Project/.../test/spots.csv'


来源:https://stackoverflow.com/questions/42970911/neo4j-nodejs-session-expire-error-how-to-fix-it

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