0

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.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
GravityL
  • 35
  • 5
  • Assuming there are vertices with that label then all you should need to do is `g.V().hasLabel("myLabel").valueMap().next()` but you also need to `await` that query returning when using the Node/Javascript client. Does that yield any results? – Kelvin Lawrence Jul 28 '21 at 01:06
  • @KelvinLawrence I'm quering like this: `return await g.V().hasLabel("myLabel").valueMap().next(); ` Got response : `{"value": null, "done": true}`. Just to be clear, there are vertex with my label inside the db – GravityL Jul 28 '21 at 14:50
  • @KelvinLawrence tried without the `.next()` and I get `[["V"],["hasLabel","myLabel"],["valueMap"]]` as a response. Also tried the same query with `person` label on the `TinkerFactory.createModern()` test db and it works as intended ¿Could this be a bug of Gremlin + Neptune? – GravityL Jul 28 '21 at 15:24
  • Without `.next()` you are not actually sending the query to Neptune as there is no "terminal" step. What you are seeing there is just the bytecode of the query that will be sent to Neptune when you add the `next()`. Which version of the Gremlin JS client are you using? Also where is your application code running? If it is in a Lambda function there may be a known issue with the Gremlin client that I can suggest a workaround for. – Kelvin Lawrence Jul 28 '21 at 16:38
  • @KelvinLawrence Yes, I'm running on lambda. It's version `3.5.1` – GravityL Jul 28 '21 at 18:00
  • OK yes - in that case you need to either handle the Map or change the serializer to return GraphSON V2 which does not include the Map type. – Kelvin Lawrence Jul 28 '21 at 23:55
  • This also happen to me and this works for me. https://stackoverflow.com/questions/75314185/valuemap-returning-empty-object-with-neptune/75325487#75325487 – Alter Feb 02 '23 at 17:24

1 Answers1

0

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.

GravityL
  • 35
  • 5