Reputation: 964
Is there a way to specify the id of a new vertex? Something like
g.addV('user', 'myId')
?
Upvotes: 7
Views: 4676
Reputation: 46206
You would do:
g.addV('user').property(id, 'myId')
which creates a vertex with the label "user" and an vertex id of "myId". Note that id
refers to T.id
.
That said, few graph databases allow id assignment so you will need to check the documentation of the implementation you are using to determine if this is even possible to do. In the case that you are using a graph that does not support id assignment you can just create an indexed property key with your special identifier and then insert it that way:
g.addV('user').property('id','myId')
Note the difference there is that "id" is now in quotes meaning it is a property name and not the token T.id
. It might be best to name that indexed property key something other than "id" to avoid confusion.
Upvotes: 11