Search code examples
databasesearchgraphgremlintinkerpop

Gremlin Queries: How to exclude ID while including label in valuemap?


So I have a gremlin query like this:

g.V().hasLabel('Person').valueMap(true, 'name')

Now this creates a valuemap with the fields/columns 'Label', 'ID' and 'name', but how do I exclude 'ID' from this?

I only want 'Label' and 'name' to be included as the results.

Any help is very much appreciated, thank you! :)


Solution

  • The other answer using WithOptions probably works, but I got an error message when I tried it (I'm sending gremlin queries as a string using an API, so it might be an error on the server-side of the API).

    However, I figured out another way to do this.

    With labels:

    g.V().hasLabel('Person').project('label', 'name').by(label).by(values('name').fold())
    

    With IDs:

    g.V().hasLabel('Person').project('id', 'name').by(id).by(values('name').fold())