Reputation: 1153
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 _id
s or is it necessary to use _key
s? I couldn't get the former to work.
Upvotes: 3
Views: 1869
Reputation: 6067
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
Upvotes: 3