Getting all ids when running adding multiple Vertices/Edges at once

21 views
Skip to first unread message

Cyril Scetbon

unread,
Dec 11, 2019, 6:22:41 PM12/11/19
to Gremlin-users
Hello,

Is there a way to get all ids instead of the last one when creating multiple vertices in one transaction ?

gremlin> g.addV('person').property('name','marko').addV('person').property('name','stephen').toList()
==>v[33]

]The last one only ^ :(

When I create an edge with 2 vertices it's easier as the edge is returned and from there I can get all ids :

gremlin> g.addV('person').property('name', 'cyril').addE('parent').to(g.addV('person').property('name', 'Aaron')).toList()
==>e[39][35-parent->37]


Thanks

Daniel Kuppitz

unread,
Dec 12, 2019, 10:11:13 PM12/12/19
to gremli...@googlegroups.com
gremlin> g.addV('person').property('name','marko').
           union(identity(),
                 addV('person').property('name','stephen'),
                 addV('person').property('name', 'daniel')).toList()
==>v[17]
==>v[19]
==>v[21]

That's the most efficient way and you can add as many addV's as you want in your union (well, there's probably a JVM limit at some point). Alternatives would be:

gremlin> g.addV('person').property('name','marko').as('p').
           addV('person').property('name','stephen').as('p').
           addV('person').property('name', 'daniel').as('p').
           select(all, 'p').next()
==>v[23]
==>v[25]
==>v[27]
gremlin> g.addV('person').property('name','marko').store('p').
           addV('person').property('name','stephen').store('p').
           addV('person').property('name', 'daniel').store('p').
           cap('p').next()
==>v[29]
==>v[31]
==>v[33]

Obviously, these two methods will require some memory, but they might be a better fit for your particular use-case.

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/8b359f8b-cebe-43e6-b0df-14abe632f40f%40googlegroups.com.

Cyril Scetbon

unread,
Dec 13, 2019, 10:07:21 AM12/13/19
to Gremlin-users
Thank you for the examples !
To unsubscribe from this group and stop receiving emails from it, send an email to gremli...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages