Rud*_*udy 1 database sockets node.js 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();
Run Code Online (Sandbox Code Playgroud)
我收到的错误是:
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)
Run Code Online (Sandbox Code Playgroud)
我不确定如何处理此错误,因为数据库似乎运行良好。我无法通过谷歌搜索此错误找到任何有用的信息;谷歌搜索“ “orientjs”“socket close” ”仅返回1个结果,所以我对如何解决这个问题有点不知所措。
任何见解都将不胜感激!
经过进一步调查,我找到了问题的根源。
事实证明,OrientDB 在两个端口上托管其服务:2480(HTTP)和 2424(二进制)。通过 OrientJS 模块连接到 OrientDB 需要使用端口 2424 而不是 2480。这解决了我的问题。