我想使用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/