在Node中,对数据库执行Gremlin查询的正确方法是什么?
我目前使用Official Node OrientDB Driver的尝试:
const { ODatabase } = require('orientjs');
const db = new ODatabase({...});
db.query('g.V()')
.then(console.log, console.error);
我得到:
OrientDB.RequestError:
Cannot find a command executor for the command request: sql.g.V()
DB name="mynevo"
at child.Operation.parseError
(.../orientjs/lib/transport/binary/protocol33/operation.js:864:13)
但是,当我在Web界面中执行g.V()
时,它运行得很好。
显然,Node驱动程序或服务器假定查询应该是SQL。有没有办法告诉它是Gremlin,还是有其他方法?
您应该能够使用执行gremlin命令
```
db.query('g.V()', {
language : "gremlin",
class : "com.orientechnologies.orient.graph.gremlin.OCommandGremlin"
}).then(function(res){
console.log(res);
})
```
对OrientDB执行gremlin查询的最简单,最快捷的方法是使用REST API(端口2480,非二进制端口2424)。这是一个电话,我建议先在邮递员中试一试。
[POST] http://:2480 / command // gremlin
然后请求正文看起来像这样:
{
"command": "g.V().has('name', 'marko')"
}
将OrientDB凭据作为基本身份验证传递
在NodeJS / JavaScript中,只需使用superagent或类似的模块来调用REST API。然后分析以JSON形式返回的结果。
另见:https://orientdb.com/docs/last/OrientDB-REST.html
在Command部分下查看