How do I delete a graph?

856 views
Skip to first unread message

m...@edcast.com

unread,
Mar 28, 2019, 11:59:03 AM3/28/19
to Gremlin-users
I am a newb to gremlin-python and want to create a graph and populate it with nodes and edges. Using the default graph 'g' I got an empty graph
I then, mostly by trial and error, learned how to add vertices one at a time by adding iterate();

graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
g.addV('person').property('name', 'bob').iterate()
g.addV('person').property('name', 'alice').iterate()

The problem is that my trial and error process added multiple duplicates:

print g.V().toList()
[v[0], v[16], v[2], v[18], v[4], v[20], v[6], v[8], v[10], v[12], v[14]]

My question is: how do I clear the graph? I could find no way of doing it from python.

thanks

Robert Dale

unread,
Mar 28, 2019, 12:04:41 PM3/28/19
to gremli...@googlegroups.com
Gremlin Server doesn't provide a way to drop graphs.  You can delete all the data in a graph.  g.V().drop().iterate()

Robert Dale


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/5b7021f8-7992-4f72-a98d-8acc322036c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

m...@edcast.com

unread,
Mar 28, 2019, 12:57:12 PM3/28/19
to Gremlin-users
Thanks!

On Thursday, March 28, 2019 at 9:04:41 AM UTC-7, Robert Dale wrote:
Gremlin Server doesn't provide a way to drop graphs.  You can delete all the data in a graph.  g.V().drop().iterate()

Robert Dale


On Thu, Mar 28, 2019 at 11:59 AM <m...@edcast.com> wrote:
I am a newb to gremlin-python and want to create a graph and populate it with nodes and edges. Using the default graph 'g' I got an empty graph
I then, mostly by trial and error, learned how to add vertices one at a time by adding iterate();

graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
g.addV('person').property('name', 'bob').iterate()
g.addV('person').property('name', 'alice').iterate()

The problem is that my trial and error process added multiple duplicates:

print g.V().toList()
[v[0], v[16], v[2], v[18], v[4], v[20], v[6], v[8], v[10], v[12], v[14]]

My question is: how do I clear the graph? I could find no way of doing it from python.

thanks

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremli...@googlegroups.com.

Stephen Mallette

unread,
Mar 30, 2019, 9:51:39 AM3/30/19
to gremli...@googlegroups.com
Just to add a little additional context. Note that you can chain your mutations so that:

g.addV('person').property('name', 'bob').iterate()
g.addV('person').property('name', 'alice').iterate()

can become:

g.addV('person').property('name', 'bob').
  addV('person').property('name', 'alice').iterate()

and thus be one request. Also, clearing a graph is as simple as Bob's answer with g.V().drop() and fine for your situation with your tiny graph that you were playing around with. However, clearing a large graph should not typically be done that way. Always look at the graph database you are using and consider its native methods for dropping/clearing a graph (which may not have python based methods for doing so)

To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/b83b5dbf-e40e-444e-a285-f82f5bd7144d%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages