Neo4j 和 Node js 中的会话过期

Log*_*gan 2 neo4j node.js

我查看了文档:

我使用以下命令创建了一个项目:

npm install --save neo4j-driver
nano index.js
Run Code Online (Sandbox Code Playgroud)

并写下了这段代码:

var neo4j = require('neo4j-driver').v1;

// Create a driver instance, for the user neo4j with password neo4j.
// It should be enough to have a single driver per database per application.
var driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "123456"));

// Register a callback to know if driver creation was successful:
driver.onCompleted = function() {
    // proceed with using the driver, it was successfully instantiated
    console.log('successfully connected');
};

// Register a callback to know if driver creation failed.
// This could happen due to wrong credentials or database unavailability:
driver.onError = function(error) {
    console.log('Driver instantiation failed', error);
};

// Create a session to run Cypher statements in.
// Note: Always make sure to close sessions when you are done using them!
var session = driver.session();
console.log(session);

session.run("CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})");

// Close the driver when application exits
driver.close();
Run Code Online (Sandbox Code Playgroud)

当我运行时收到此错误消息node index.js

驱动程序实例化失败 { [错误:套接字挂起] 代码:'SessionExpired' }

我探索过:

我已将密码设置为123456首次启动后的密码http://localhost:7474/browser/

我使用的是 Windows 10。在防火墙方面我需要做什么?我缺少什么?

编辑:我正在使用 Neo4j 3.1.2

std*_*b-- 6

问题是session.run函数是异步的并返回承诺。

但是您关闭会话,直到它执行并准备好返回结果为止。

尝试这个:

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

driver.onCompleted = function() {
    console.log('successfully connected');
};
driver.onError = function(error) {
    console.log('Driver instantiation failed', error);
};

var session = driver.session();
console.log(session);    
session
    .run(`
        CREATE (TheMatrix:Movie { title:'The Matrix', 
                                  released:1999, 
                                  tagline:'Welcome to the Real World'
        })
        RETURN TheMatrix
    `)
    .then( function(result) {
        console.log(result);
        driver.close();
    })
    .catch( function(error) {
        console.log(error);
        driver.close();
    })
Run Code Online (Sandbox Code Playgroud)