node.js - 使用 OrientJS 模块连接到 NodeJS 中的 OrientDB -- "Socket Closed"错误

标签 node.js database sockets orientdb orientjs

我正在使用 OrientJS (v2.2.10) 在 NodeJS (v8.11.3) 中开发一个应用程序,它将连接到本地托管的 OrientDB (v3.0.6) 数据库并进行查询。但是,当我尝试运行我的程序时,我每次都会收到“套接字已关闭”错误。

我能够连接到数据库并通过 OrientDB 的控制台和 Web 界面查询它,所以我知道可以通过地址 http://localhost:2480 访问数据库。 .如果我在命令提示符下运行“netstat -a”,我可以看到端口 2480 正在监听 TCP 连接。

这是我目前正在运行的代码:

//Import OrientJS driver for OrientDB
var OrientJs = require('orientjs');

//Connect to OrientDB server
var server = OrientJs({
    host: "localhost",
    port: "2480",
    username: "root",
    password: "root"
});

//Connect to 'demodb'
var db = server.use({
    name: 'demodb',
    username: 'root',
    password: 'root'
});

console.log("Connected to database")

//Select all entries in 'Castles' table and print to console
db.select().from('Castles').all()
.then(function(result) {
  console.log(result);
});

//Close connection to database
db.close();

我收到的错误是:

Unhandled rejection OrientDB.ConnectionError [0]: Socket Closed
    at Connection.<anonymous> (C:\Program Files\nodejs\apollo_server\node_modules\orientjs\lib\transport\binary\connection.js:277:16)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

我不确定这个错误是怎么回事,因为数据库似乎运行良好。通过谷歌搜索此错误,我无法找到任何有用的信息;谷歌搜索 ""orientjs""socket closed"" 只返回 1 个结果,所以我对如何解决这个问题有点不知所措。

非常感谢任何见解!

最佳答案

经过进一步排查,我找到了问题的根源。

事实证明,OrientDB 在两个端口上托管其服务:2480 (HTTP) 和 2424(二进制)。通过 OrientJS 模块连接到 OrientDB 需要使用端口 2424 而不是 2480。这解决了我的问题。

关于node.js - 使用 OrientJS 模块连接到 NodeJS 中的 OrientDB -- "Socket Closed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51903645/

相关文章:

Java线程中断后处于 Activity 状态

sockets - 了解套接字名称

node.js - 如何使用 Angular 2+、Express 和 nodeJs 上传文件

mysql - 如何更改此查询,以便在 select(*) 计数值为 2 时返回 true?

python - MySQL 的数据库版本控制

java - 还有其他更好的方法来获取和比较数据库凭证与java吗?

c# - 如何使用 C# 4.0 编写可扩展的套接字服务器?

node.js - 在Plesk Onyx中安装其他 Node 版本

javascript - 加载 Express-routed Partial 后触发 AngularJS

node.js - 错误 : SyntaxError: Unexpected end of JSON input