Node.js 在gremlinjavascript中使用谓词
我想使用gremlinjavascript遍历远程图形并获得顶点列表,其id位于预定义id列表中Node.js 在gremlinjavascript中使用谓词,node.js,gremlin,tinkerpop,tinkerpop3,gremlin-server,Node.js,Gremlin,Tinkerpop,Tinkerpop3,Gremlin Server,我想使用gremlinjavascript遍历远程图形并获得顶点列表,其id位于预定义id列表中 const gremlin = require('gremlin'); const Graph = gremlin.structure.Graph; const GraphPredicate = gremlin.process.P; const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection; const graph =
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控制台进行测试时,它给出了结果中的顶点(414)
:> g.V().hasId(within(414,99999))
所以我这里有一些问题:
- 为了使用谓词,我是否遗漏了配置中的某些内容
- 在javascript的方法中,GraphPredicate.within([41499999])参数是否应该是元素数组或用逗号分隔的元素列表?顺便说一句,我两种方法都试过了,但结果总是空的
提前感谢您,id是TinkerPop中的一个特殊属性,无法使用name属性
“id”
检索
在您的案例中,通过ID检索的正确方法应该是:
g.V().hasId(P.within(414, 99999)).toList()
.then(result => console.log(result));
此外,可以通过删除()中的
调用来简化此过程:
g.V().hasId(414, 99999).toList()
.then(result => console.log(result));
id是TinkerPop中的特殊属性,无法使用name属性
“id”
检索
在您的案例中,通过ID检索的正确方法应该是:
g.V().hasId(P.within(414, 99999)).toList()
.then(result => console.log(result));
此外,可以通过删除()中的
调用来简化此过程:
g.V().hasId(414, 99999).toList()
.then(result => console.log(result));
我不能评论,但是为了使用
id
,您需要使用gremlin.process.t.id
例如:
在Gremlin.by(id)
在JS
.by(gremlin.process.t.id)
希望这有帮助我不能评论,但是为了使用
id
,您需要使用gremlin.process.t.id
例如:
在Gremlin.by(id)
在JS
.by(gremlin.process.t.id)
希望这对您有所帮助是的,您的两种解决方案都有效。但是,当我将其应用于过滤边的顶点时,它似乎不起作用。如果我在一个步骤
outE('LIKE').inV()或inE('LIKE').outV()之后调用hasId(2,3)
或hasId(P.within(2,3))
,它将始终给我一个空结果,尽管我确信结果中应该有顶点2,3。此外,当我仅使用一个id调用时,hasId(2)
,我会让结果中的顶点2同意不可能简单地使用“id”
在查询中引用id。然而,我碰巧知道我们可以通过使用它的枚举值来引用它。可以从gremlin.process.t.id
访问该值。例如,g.V()。它将允许您保存一个引用,引用您希望从遍历中返回的值,并在稍后的终端步骤之前返回这些值。是的,您的两种解决方案都有效。但是,当我将其应用于过滤边的顶点时,它似乎不起作用。如果我在一个步骤outE('LIKE').inV()或inE('LIKE').outV()之后调用hasId(2,3)
或hasId(P.within(2,3))
,它将始终给我一个空结果,尽管我确信结果中应该有顶点2,3。此外,当我仅使用一个id调用时,hasId(2)
,我会让结果中的顶点2同意不可能简单地使用“id”
在查询中引用id。然而,我碰巧知道我们可以通过使用它的枚举值来引用它。可以从gremlin.process.t.id
访问该值。例如,g.V()。它将允许您保存一个引用,引用您确实希望从遍历中返回的值,并在稍后的终端步骤之前返回这些值。