Skip to content
Advertisement

Gremlin’s valueMap() returns an empty object with JS and Neptune

I’m trying to get all the nodes and it’s properties with gremlin and js that has a specific label.

It should output something like:

[
  { 
    p1:v1,
    p2:v2,
    px:vx
  },
  { 
    p1:v1,
    p2:v2,
    px:vx
  }
]

I tried a million things now, but I think it’s supposed to work with:

g.V().hasLabel("myLabel").valueMap();

or

g.V().hasLabel("myLabel").map(p.valueMap()).toList();

But both of them returns

[
  {},
  {}
]

Which I don’t understand, because if I do this:

g.V().hasLabel("myLabel").map(p.values().fold()).toList();

I got a list like I want but only with the values.

Advertisement

Answer

Turns out that Gremlin returns a Map instead of an Object, so I needed to cast the response as an object before I was able to use it.

Here’s how I’m doing it:

const response = await g.V().hasLabel("myLabel").local(p.properties().group().by(p.key()).by(p.value())).toList();
const asObject = response.map(val=>Object.fromEntries(val));

I’ve also opted for local instead of valueMap() because the last one will return the values as arrays instead of the actual value.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement