Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

graph - Gremlin remove all Vertex

I know how to remove a vertex by id, but I need to delete multiple vertices (clean the db).

Deleting 1 v is like this:

ver = g.v(1)
g.removeVertex(ver)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In more recent terms as of Gremlin 2.3.0, removal of all vertices would be best accomplished with:

g.V.remove()

UPDATE: For version Gremlin 3.x you would use drop():

gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().drop().iterate()
gremlin> graph
==>tinkergraph[vertices:0 edges:0]

Note that drop() does not automatically iterate the Traversal as remove() did so you have to explicitly call iterate() for the deletion to occur. Iteration in the Gremlin Console is discussed in detail in this tutorial.

Also, consider that different graph systems will potentially have their own methods for more quickly and efficiently removing all data in that system. For example, JanusGraph has this approach:

 JanusGraphFactory.drop(graph)

where "graph" is a JanusGraph instance you want cleared out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...