gpt4 book ai didi

node.js - Neo4j 和 Node js 中的 session 过期

转载 作者:太空宇宙 更新时间:2023-11-04 03:05:11 27 4
gpt4 key购买 nike

我查看了文档:

我使用这些命令创建了一个项目:

npm install --save neo4j-driver
nano index.js

并编写了这段代码:

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

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

Driver instantiation failed { [Error: socket hang up] code: 'SessionExpired' }

我探索过:

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

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

编辑:我正在使用 Neo4j 3.1.2

最佳答案

问题在于 session.run 函数是异步的并返回 promise 。

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

试试这个:

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

关于node.js - Neo4j 和 Node js 中的 session 过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43024485/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com