0
votes

Summary

I am writing a gremlin script to work for both orientdb and neo4j.

For a sample, purposes let say we want to load a vertex with id 1 for neo4j, we will write the gremlin script as g.V(1) and for orientDB g.V('#17:0').

such that my script should run for both the databases?

1

1 Answers

2
votes

You can't have a vendor independent element identifier as most graph systems don't let you assign the identifier and neither Neo4j or OrientDB allow for that. You likely shouldn't be hardcoding identifiers in your code anyway as I believe that those can change out from under you depending on the graph system.

The correct approach would be to rely on indices and prefer to write your traversals as:

g.V().has('myId', 1234)

in which case any graph database could resolve that. If you do work with the native graph identifiers, I suggest you always treat them as variables in your code as in:

Object vid = g.V().has('myId', 1234).id().next()
...
g.V(vid).out().....