2

我按照以下说明创建了一个带有 neo4j 的谷歌云 VM 实例: https ://neo4j.com/docs/operations-manual/current/cloud-deployments/neo4j-gcp/single-instance-vm/

浏览器 Db 看起来不错:我可以从浏览器查看和操作。

问题是在尝试使用 neo4j-driver npm 从 nodejs 连接 neo4j 时。

我不断收到此错误:

UnhandledPromiseRejectionWarning: Neo4jError: Connection was closed by server

这是代码:

const neo4j = require('neo4j-driver')
const uri = 'bolt://[EXTERNAL_IP]:[PORT]'
const user = 'USER_NAME'
const password = 'PASSWORD'

const createPerson = async () => {
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password), { encrypted : "ENCRYPTION_OFF"})
const session = driver.session()
const personName = 'Bob'
    try {
        const result = await session.run(
          'CREATE (a:Person {name: $name}) RETURN a',
          { name: personName }
        )

    const singleRecord = result.records[0]
    const node = singleRecord.get(0)

    console.log(node.properties.name)
  } finally {
    await session.close()
  }

  // on application exit:
  await driver.close()
}

createPerson()

代码取自此链接:https ://neo4j.com/developer/javascript/

我运行这个命令:gcloud compute ssh my-neo4j-instance在 GCP shell 中,希望添加 ssh 可以解决问题,但它没有。

将驱动程序加密选项更改为 false 也无济于事。

控制台记录错误打印:

Neo4jError: Connection was closed by server

at captureStacktrace (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\result.js:263:15)
at new Result (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\result.js:68:19)
at Session._run (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\session.js:174:14)
at Session.run (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\session.js:135:19)
at createPerson (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\src\index.js:12:38)
at Object.<anonymous> (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\src\index.js:31:1)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14) {


code: 'ServiceUnavailable',
  name: 'Neo4jError'

我错过了什么?

编辑1:

我查看了谷歌云日志。我看到的只是虚拟机启动和停止的日志。

另外,我修复了主文件中异步函数调用的代码。所以而不是

 createPerson();

我试过这个:

(async() => {
console.log('before start');

await createPerson();

console.log('after start');
})();

仍然不好,仍然:Neo4jError:连接已被服务器关闭。我也在 neo4j 博客中问过,但没有得到任何答案。

编辑2:

我在另一个堆栈溢出帖子中看到了我的问题。答案是通过更改密码来完成对 neo4j 的记录。但我已经这样做了......我也加入了 neo4j 松弛组,但仍然没有得到答案。

4

0 回答 0