首页 > 解决方案 > Why is hasId() only returning one of the ids in a list?

问题描述

I'm using javascript gremlin to get results based on a list of ids:

await g
    .addV("test")
    .property(id, "1")
    .addV("test")
    .property(id, "2")
    .next();

const result = await g
    .V()
    .hasId("1","2")
    .next()

result only contains id 1: {"value":{"id":"1","label":"test"},"done":false}

If I hop on the console, I get the expected result.

g.V().hasId("1","2")
==>v[1]
==>v[2]

Why is there a discrepancy between these results?

The JS is running in AWS Lambda on Node 10.x.

gremlin: 3.4.2

GraphSON v2

标签: gremlin

解决方案


您看到的这种差异是 Gremlin 控制台在遇到控制台时的工作方式的结果,Iterator它会自动迭代所有答案。在 JS 中,您必须使用Iterator命令。

使用Iterator.next()时结果将是迭代器中的下一个值。如果你想获得我会使用的所有值toList

const result = await g
    .V()
    .hasId("1","2")
    .toList()

推荐阅读