如何使用 id 获取所有属性

How to get all properties with the ids

我对所有图形数据库都是新手,我很难处理一些基本查询。 我将 Gremlin 与 Kotlin 结合使用以连接到 AWS Neptune。 我想获取所有顶点属性,包括 Id。

我添加了一个顶点:

g.addV("foo")
    .property("name", "Foo 1")
    .next()

并检索我尝试过的属性:

g.V()
    .hasLabel("foo")
    .valueMap<String>()
    .by(unfold<String>())
    .forEach {
        // val name = it["name"] -> works great!
        // val id = it["id"] -> doesn't exist
    }

在第一种方法中,我得到了每个项目的地图,但该地图不包含 ID。

g.V()
    .hasLabel("foo")
    .forEach {
        // it is an ReferenceVertex that has an ID!
        val name = it.property<String>("name") // This returns an EmptyVertexProperty, so I can't read the name
    }

我正在使用

<dependency>
    <groupId>org.apache.tinkerpop</groupId>
    <artifactId>gremlin-driver</artifactId>
    <version>3.4.4</version>
</dependency>

加分题

我无法弄清楚(也无法在文档中找到)valueMapunfold 方法上的泛型的作用。 Kotlin 不允许我省略它们(正如我在一些 java 代码中看到的那样......?),但是将它们更改为 Int,例如,这些示例的结果没有任何改变.. . 那它是做什么用的呢? D:

提前致谢!

如果您想要获得具有所有其他属性的 Id,您需要 运行 valueMap().with(WithOptions.tokens) 或者您可以使用 elementMap().