Learn GREMLIN with Real Code Examples
Updated Nov 18, 2025
Code Sample Descriptions
1
Basic Gremlin Traversals
g.V().has("person", "name", "Alice")
.out("knows")
.values("name")
Traversing a graph to find friends of a person using Gremlin.
2
Add Vertex and Edge
g.addV("person").property("name", "Alice")
.addV("person").property("name", "Bob")
.addE("knows").from(g.V().has("name","Alice")).to(g.V().has("name","Bob"))
Adding vertices and an edge between them in Gremlin.
3
Filter by Property
g.V().hasLabel("person").has("age", gt(30)).values("name")
Finding people older than 30 in a Gremlin graph.
5
Shortest Path Traversal
g.V().has("person","name","Alice")
.repeat(out().simplePath()).until(has("person","name","Bob"))
.path()
Finding a simple path between two people.
6
Group By Property
g.V().hasLabel("person")
.group().by("city")
.next()
Grouping people by their city property.
7
Order Vertices
g.V().hasLabel("person")
.order().by("age", decr)
.values("name","age")
Ordering people by age in descending order.
8
Limit Traversal Results
g.V().hasLabel("person").limit(5).values("name")
Limiting the traversal to return only 5 people.
9
Remove Vertex
g.V().has("person","name","Alice").drop()
Deleting a vertex with a given property.
10
Traversal with Both Directions
g.V().has("person","name","Alice")
.both("knows")
.values("name")
Finding all friends connected in both directions.