I'm creating some removal queries for vertices and edges in ArangoDB using AQL and I assumed there would be a "safe" way to delete vertices that would also remove associated edges. But I can't find any in the documentation or anywhere else. Is the following the best way to do a safe delete?
FOR e IN GRAPH_EDGES('EdgeClass',docId,{direction:'any',maxDepth:1, includeData:false})
REMOVE e._key FROM EdgeClass
combined with
REMOVE docKey IN DocumentClass
Also, is there a way to remove vertices (or edges) using _ids or is it necessary to use _keys? I couldn't get the former to work.
Deleting vertices is currently not handled via AQL. The graph management interface offers vertex deletion functionality.
The programming language specific driver usually offers wrappers for the REST interfaces to these methods.
If you want to design an AQL query that does this for you, you'd i.e. have to know whether a vertex is only used in one graph, and the number of edge collections that could be concerned by this deletion. You would probably want to use the more modern graph traversals. Lets try to remove eve from the knows graph:
LET keys = (
FOR v, e IN 1..1 ANY 'persons/eve' GRAPH 'knows_graph' RETURN e._key)
LET r = (FOR key IN keys REMOVE key IN knows) REMOVE 'eve' IN persons
So, we let the the traversal give us the _key of all edges of Eve. We then remove all these edges from the knows edge collection. After that we remove Eve herself.
However, you can easily see that you have to craft such a query specific for your situation.
edit: one can do this a little more elegant like this:
LET keys = (FOR v, e IN 1..1 ANY 'persons/eve' GRAPH 'knows_graph'
REMOVE e._key IN knows)
REMOVE 'eve' IN persons
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With