g.v(1).id
gives me vertex 1 id,
g.v(1).map
gives me vertex 1 properties.
But, how can I get a hash with id and propeties at the same time
Just extending on @Stephen's answer; to get the id and the map() output in a nice single Map for each Vertex , just use the plus or leftShift Map operations in the transform method.
To create a new edge between two vertices, use the addEdge(v1, v2, label) method. The edge will be created with the label specified. In the example below two vertices are created and assigned to a variable (Gremlin is based on Groovy), then an edge is created between them.
If you have the vertex already then simply v. remove() . Any of the 3 will serve.
outV Outgoing vertex. inV Incoming vertex. How on earth Incoming vertex = the vertex at the other end of the outgoing edge. If anything, i would think that the vertex at the other end of the outgoing edge if the OutV and not InV.
I know that it's an old question - so answers below will work on older versions of TinkerPop (3<); just if anyone (like me) stumbles upon this question and looks for a solution that works on TinkerPop 3 - the same result can be achieved by calling valueMap with 'true' argument, like this:
gremlin> g.v(1).valueMap(true)
reference may be found in docs here
As of Gremlin 2.4.0 you can also do something like:
gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.v(1).out.map('name','age','id')
==>{id=2, age=27, name=vadas}
==>{id=4, age=32, name=josh}
==>{id=3, age=null, name=lop}
Another alternative using transform():
gremlin> g.v(1).out.transform{[it.id,it.map()]}
==>[2, {age=27, name=vadas}]
==>[4, {age=32, name=josh}]
==>[3, {name=lop, lang=java}]
if implementing with Java use
g.V(1).valueMap().with(WithOptions.tokens).toList()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With