0

I don't want the same vertex to be traversed again, but I am not able to use otherV in CosmosDB Gremlin API. Is there an alternative for that?

1 Answers1

2

You don't have an example of your usage but sometimes I see folks do this:

gremlin> g.V(1).bothE().otherV() 
==>v[3]
==>v[2]
==>v[4]

which is really just:

gremlin> g.V(1).both()
==>v[3]
==>v[2]
==>v[4]

The latter is cheaper. You would only need otherV() in scenarios where you need to filter edges:

gremlin> g.V(1).bothE().has('weight',gt(0.4)).otherV() 
==>v[2]
==>v[4]

If you have this more legitimate situation where otherV() is needed you can implement a filter of your own with a step label and where() like:

gremlin> g.V(1).as('a').bothE().has('weight',gt(0.4)).union(inV(),outV()).where(neq('a'))
==>v[2]
==>v[4]
stephen mallette
  • 45,298
  • 5
  • 67
  • 135