Cheatography
https://cheatography.com
Gremlin Graph Database Query Examples
Get a Single Vertex with All Properties Listed
%%gremlin
g.V("981b646a-923f-436e-bb39-59bdee568da3").valueMap(true).unfold()
|
Get Vertices by a Label
%%gremlin
g.V()
.hasLabel("Customer")
.valueMap(true)
|
Get Other Vertices by Outer Edge
//Get Invoices for a Customer
%%gremlin
g.V("371285d7-3d78-4e01-8386-87aac4a5b9da")
.outE("HAS_INVOICE")
.project("id", "invoiceDate", "invoiceTotal")
.by(otherV().id())
.by(otherV().values("invoiceDate"))
.by(otherV().values("invoiceTotal"))
.toList()
|
Get Vertices by Properties
//Get all customers with a Beverly Hills shipping zip code that live in an apartment
%%gremlin
g.V()
.hasLabel("Customer")
.has("ShippingZip", 90210)
.has("ShippingAddress", containing("APT"))
.valueMap(true)
|
Count for a Label
%%gremlin
g.V()
.hasLabel("Customer")
.count()
|
|
|
Add Vertex and Get The ID
%%gremlin
g.addV("Customer")
.property("FirstName", "Luke")
.property("LastName","Starbucker")
.project("id")
.by(T.id)
|
Update Vertex
%%gremlin
g.V("3f3d7d90-8a50-44e0-b6a3-9100ffc1c7d5")
.property(Cardinality.single, "FirstName", "Ham")
.property(Cardinality.single, "LastName", "Salad")
|
Delete Vertex
%%gremlin
g.V("f1fd1846-5bc6-4395-af86-77227c500199").drop()
|
Get All Property Names for All Vertices
%%gremlin
g.V()
.properties()
.groupCount()
.by(key())
.unfold()
|
Get All Labels
%%gremlin
g.V()
.groupCount()
.by(label())
.unfold()
|
|
Created By
www.kellermansoftware.com
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by GregFinzer