Skip to content

Instantly share code, notes, and snippets.

@ghstahl
Created January 27, 2019 16:44
Show Gist options
  • Save ghstahl/9010fac580c852888ad8f97c9411ecc7 to your computer and use it in GitHub Desktop.
Save ghstahl/9010fac580c852888ad8f97c9411ecc7 to your computer and use it in GitHub Desktop.
gremlin simple queries
1. Add
g.addV('template').property('id', '061430dc-a267-4140-964d-a046470c9273').property('category','cat1').property('version','1.0.0')
g.addV('cct').property('id', '762d3cc4-2447-46d3-aa6d-ad3bc17444b6').property('category','cctCat1').property('version','1.0.0')
g.addV('colp').property('id', '067a6bb2-19da-4d6c-af46-b66473b04c35').property('category','colpCat1').property('version','1.0.0')
2. Find by id
g.V('061430dc-a267-4140-964d-a046470c9273')
3. add a new property
g.V('061430dc-a267-4140-964d-a046470c9273').property('a','b')
4. remove property
g.V('061430dc-a267-4140-964d-a046470c9273').properties('a').drop()
5. Add edge if it doesn't exist already
g.V('061430dc-a267-4140-964d-a046470c9273').as('v').
V('762d3cc4-2447-46d3-aa6d-ad3bc17444b6').
coalesce(__.inE('has').where(outV().as('v')),
addE('has').from('v'))
g.V('061430dc-a267-4140-964d-a046470c9273').as('v').
V('067a6bb2-19da-4d6c-af46-b66473b04c35').
coalesce(__.inE('has').where(outV().as('v')),
addE('has').from('v'))
6. Find edge between 2 vertices
g.V('061430dc-a267-4140-964d-a046470c9273').bothE().where(otherV().hasId('762d3cc4-2447-46d3-aa6d-ad3bc17444b6'))
g.V('061430dc-a267-4140-964d-a046470c9273')
.outE('has').where(otherV().hasId('762d3cc4-2447-46d3-aa6d-ad3bc17444b6'))
7. Find all V that has in in 'has'
g.V('061430dc-a267-4140-964d-a046470c9273').outE('has').inV()
7. Drop the edge
g.V('061430dc-a267-4140-964d-a046470c9273')
.bothE().where(otherV().hasId('762d3cc4-2447-46d3-aa6d-ad3bc17444b6')).drop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment