node.js - 在 gremlin javascript 中使用谓词

标签 node.js gremlin tinkerpop tinkerpop3 gremlin-server

我想使用gremlin-javascript遍历远程图并获取顶点列表,其ID位于预定义ID列表中。

const gremlin = require('gremlin');
const Graph = gremlin.structure.Graph;
const GraphPredicate = gremlin.process.P;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;

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

g.V()
    .has('id', GraphPredicate.within([414, 99999]))
    .toList()
    .then(function (result) {
        console.log(result);
    });

上面是我尝试过的代码,但它给了我一个空的顶点列表,而我期望结果中有一个顶点(414)

此外,当我使用下面的语句使用 gremlin-console 进行测试时,它在结果中给出了顶点(414)

:> g.V().hasId(within(414,99999))

所以我有一些问题:

  • 为了使用 Predicate,我是否遗漏了配置中的某些内容?
  • 在 javascript 方法中 GraphPredicate.within([414, 99999])) 参数应该是仅是一个元素数组用逗号分隔的元素列表(如 gremlin-console 的情况)?顺便说一下,两种方法我都试过了,但总是得到空结果。

提前谢谢您,

最佳答案

id 是 TinkerPop 中的一个特殊属性,无法使用名称属性 "id" 检索。

在您的情况下通过 ids 检索的正确方法应该是:

g.V().hasId(P.within(414, 99999)).toList()
  .then(result => console.log(result));

此外,这可以通过删除 within() 调用来简化:

g.V().hasId(414, 99999).toList()
  .then(result => console.log(result));

关于node.js - 在 gremlin javascript 中使用谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50782640/

相关文章:

node.js - Node JS 和 EJS POST

graph-databases - 如何列出正在运行的 gremlin 查询?如何取消运行缓慢或长时间运行的查询?

gremlin - 海王星下降顶点属性并确认

javascript - 工作 gremlin javascript 示例

java - Gremlin-driver 无法获得 titandb 的响应

gremlin - 如何使用 Gremlin API 在 Cosmos DB 中进行简单计算

gremlin - 根据边缘属性对路径进行排序

node.js - 浏览器控制台错误: Cannot find module 'react-dom/lib/ReactPerf' from 'react/lib/ReactAddonsDOMDependencies.js'

node.js - 是否可以从 socket.io-emitter 广播

node.js - 在 POST 上获取 ng-model 值到 Express.js 端点