How to get the T.id from map in Javascript-gremlin

51 views
Skip to first unread message

Yaara Zegelman

unread,
Jan 9, 2022, 3:30:35 PMJan 9
to Gremlin-users
Hi,
I'm using gremlin-javascript 3.5.1 (actually typescript but it doesn't matter).
With the following code:
const results = g.V().limit(1).elementMap("Name").toList();
const map = results[0];

map is:
Map(4) { EnumValue { typeName: 'T', elementName: 'id' } => 337469, EnumValue { typeName: 'T', elementName: 'label' } => 'Person', 'Name' => 'John', } When I try to fetch the T.id and T.label (like in python) it fails:
var gremlin = require("gremlin");
const T = gremlin.process.t
map.get(T.id) // undefined map.keys().next().value // EnumValue { typeName: 'T', elementName: 'id' } map.keys().next().value == T.id // false 

Any help would be much appreciated, thanks! Yaara

Kelvin Lawrence

unread,
Jan 11, 2022, 2:35:34 PMJan 11
to Gremlin-users
Here is a snippet that works for me (I'm not showing all the connection setup pieces)

const { t,order,cardinality,column,scope,pop,operator,P,traversal } = gremlin.process;

async function runTests() {
  try {
    let trv= g.V('3');
    trv = trv.valueMap(true);
    const result = await trv.next();
    console.log(result);
    console.log(result.value.size);
    console.log(result.value.get('code'));
    console.log(result.value.get(t.id));
  } catch(e) {
      console.error(`Something went wrong:\n ${e}`);
  } finally {
      await connection.close();
  }
}


when run this yields

{ value:
   Map {
     'country' => [ 'US' ],
     'code' => [ 'AUS' ],
     'longest' => [ 12250 ],
     'city' => [ 'Austin' ],
     EnumValue { typeName: 'T', elementName: 'id' } => '3',
     'lon' => [ -97.6698989868164 ],
     'type' => [ 'airport' ],
     EnumValue { typeName: 'T', elementName: 'label' } => 'airport',
     'elev' => [ 542 ],
     'icao' => [ 'KAUS' ],
     'runways' => [ 2 ],
     'region' => [ 'US-TX' ],
     'lat' => [ 30.1944999694824 ],
     'desc' => [ 'Austin Bergstrom International Airport' ] },
  done: false }
14
[ 'AUS' ]
3

Yaara Zegelman

unread,
Jan 23, 2022, 3:09:00 AMJan 23
to Gremlin-users
Thanks Kelvin!!
This works for me too.

Not sure why this works and what I tried doesn't, but nevermind haha

Reply all
Reply to author
Forward
0 new messages