【问题标题】:How to execute Gremlin against OrientDB using orientjs?如何使用 orientjs 对 OrientDB 执行 Gremlin?
【发布时间】:2017-03-26 19:16:17
【问题描述】:

在 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,还是有其他方法?

【问题讨论】:

    标签: node.js orientdb gremlin


    【解决方案1】:

    您应该能够使用 gremlin 命令执行

    ```

    db.query('g.V()', { 
            language : "gremlin", 
            class : "com.orientechnologies.orient.graph.gremlin.OCommandGremlin"
        }).then(function(res){
            console.log(res);
        })
    

    ```

    【讨论】:

    • 谢谢!另外,你知道如何注入参数吗?无论我尝试什么,它都会显示“没有这样的属性:类的 p1:Script17”......例如:g.V().has('name', p1){params: { p1: 'Alan' }}
    【解决方案2】:

    对 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

    查看命令部分

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-18
      相关资源
      最近更新 更多