Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在gremlinjavascript中使用谓词_Node.js_Gremlin_Tinkerpop_Tinkerpop3_Gremlin Server - Fatal编程技术网

Node.js 在gremlinjavascript中使用谓词

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 =

我想使用gremlinjavascript遍历远程图形并获得顶点列表,其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控制台进行测试时,它给出了结果中的顶点(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()。它将允许您保存一个引用,引用您确实希望从遍历中返回的值,并在稍后的终端步骤之前返回这些值。