Skip to content

Instantly share code, notes, and snippets.

@garymacindoe
Created November 5, 2018 10:08
Show Gist options
  • Save garymacindoe/22179da58a3defb0520b61624d4e7002 to your computer and use it in GitHub Desktop.
Save garymacindoe/22179da58a3defb0520b61624d4e7002 to your computer and use it in GitHub Desktop.
Query to change the ID of a vertex using Gremlin
g.V()
// Find (single) vertex to change
.as('old')
.addV(select('old').label())
.as('new')
.property(id, new_id) // Insert new ID for vertex here
.sideEffect(
select('old')
.properties()
.unfold()
.as('p')
.select('new')
.property(
select('p').key(),
select('p').value()
)
)
.sideEffect(
select('old')
.inE()
.unfold()
.as('in')
.outV()
.addE(select('in').label())
.to('new')
.as('new')
.select('in')
.properties()
.unfold()
.as('p')
.select('new')
.property(
select('p').key(),
select('p').value()
)
)
.sideEffect(
select('old')
.outE()
.unfold()
.as('out')
.inV()
.addE(select('out').label())
.from('new')
.as('new')
.select('out')
.properties()
.unfold()
.as('p')
.select('new')
.property(
select('p').key(),
select('p').value()
)
)
.select('old').drop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment