Is it possible to dynamically construct a WITH statement? I have to do a graph traversal, but I don't know in advance which collections contain the graph nodes. I have tried to create the statement dynamically, but I keep getting strange errors that don't seem to have anything to do with that. I collect all the collection names from the document handles in the query and I create a comma separated list of collection names that I dynamically inject into the query.
For cluster deployments, it is necessary to declare the possibly involved collections upfront when you use graph traversals. More specifically:
FOR v,e,p 1..1 OUTBOUND "vertex/start" ...
) and the collection isn't explicitly declared otherwise.... OUTBOUND "vertex/start edgeColl1, edgeColl2
as opposed to ... OUTBOUND "vertex/start" GRAPH "aNamedGraph"
) unless they are explicitly declared elsewhere in the query.DOCUMENT()
function. This isn't a requirement but could help to avoid deadlocks.Calculating the collections for WITH
at runtime isn't possible as that is too late for the query engine. It needs to prepare a cluster query with this knowledge for deterministic locking, which is necessary to avoid deadlocks, and there might also be some setup for traversals that requires knowledge about the involved collections.