Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of Objects instead of a list of Maps in gremlin-javascript

Hi I am now using gremlin -javascript to do some queries in AWS neptune DB. I have a query like

[errRelatedTicket, relatedTicket] = await to(g.V().hasId(a).in_('r').valueMap(true).toList());

then I get a list of map like:

[
 Map {
   id: 1
 },
 Map {
   id: 2
 },
]

But can I use gremlin query to get id and properties in key/value pairs directly instead? what I expect is:

[
  { id: 1 },
  { id: 2 },
]
like image 358
Hongli Bu Avatar asked Jan 17 '26 09:01

Hongli Bu


1 Answers

I don't know "gremlin-javascript", you can research more in the document. But I know there's a simple way to do the conversion in plain javascript, use .map and Object.fromEntries. Hope you'll find a better way.

var listMap = [ 
  new Map([[ 'id', 1 ]]),
  new Map([[ 'id', 2 ]]),
];

var listObject = listMap.map(m => Object.fromEntries(m));

console.log(listObject);
like image 81
Loi Nguyen Huynh Avatar answered Jan 19 '26 21:01

Loi Nguyen Huynh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!