【问题标题】:How do I use tryNext() in Gremlin with Node.js?如何在 Gremlin 中通过 Node.js 使用 tryNext()?
【发布时间】:2019-05-27 14:27:28
【问题描述】:

以下示例不适用于我在 Node.js 中使用 'gremlin' 3.4.1 npm 包:

g.V().has('person','name','bill').tryNext().orElseGet{g.addV('person').property('name','bill').next()}

我收到一个 TypeError 说 tryNext() 不是函数。我做错了什么?

import {driver, structure} from 'gremlin';
import DriverRemoteConnection = driver.DriverRemoteConnection;
import Graph = structure.Graph;

const g = new Graph().traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'));

console.log(g.V().toList());    <= working

现在在该代码中使用上面的行将不起作用,但使用 Gremlin 控制台可以工作。

【问题讨论】:

    标签: node.js gremlin


    【解决方案1】:

    试图调用一个不存在的函数,这似乎如 Gremlin 文档中所述:

    tryNext() 将返回 Optional,因此,它是 hasNext()/next() 的组合(仅支持 JVM 语言)。

    http://tinkerpop.apache.org/docs/current/reference/#terminal-steps

    警告:从未使用过 TinkerPop,从未使用过 Gremlin。但我知道如何使用网络。可能这是错误的,但文档看起来确实很清楚。

    【讨论】:

      【解决方案2】:

      如果 tryNext() 正如 Dave 提到的那样不受支持。

      您可以重写查询以对其他 gremlin 步骤执行相同操作:

      g.V().has('person','name','bill').fold().coalesce(unfold(),g.addV('person').property('name','bill')).next()
      
      

      【讨论】:

      • 我得到展开未定义错误,如何解决?
      • 听起来不太可能不支持unfold。您是否在这里运行了相同的查询?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多