Is it possible to create edges and vertexes simultaneously in ArangoDB

780 views Asked by At

Is it possible to create edges by specifying documents that may or may not exist, and create them when they don't?

For instance, if I run a query like:

INSERT {_to: 'docs/something', _from: 'docs/other'} IN edges

If either docs/something or docs/other don't exist already, I'll get an error. Is there an option I could pass that would create docs/something and docs/other (as an empty object, perhaps) if they didn't exist?

Note: I can do a bulk import and create edges without documents - _to and/or _from just lead to nowhere - but I'd rather create a blank document

1

There are 1 answers

0
dothebart On BEST ANSWER

One of the features of Managed Graphs is, that it ensures graph integrity. Thus using the edge management facility will end in ArangoDB not permitting the insertion of dangling edges.

However, ArangoDBs graph functionality is layered on top of document functionality. The document functionality does not warant graph integrity; thus inserting edges referencing non existant vertices is possible this way and your example query will work if the edge collection exists.

However, quoting the insert documentation:

Each INSERT operation is restricted to a single collection,
and the collection name must not be dynamic. 
Only a single INSERT statement per collection is allowed per AQL query,
and it cannot be followed by read operations that access 
the same collection, by traversal operations,
or AQL functions that can read documents.

So you won't be able to create vertices dynamically with AQL in the same query.

With ArangoDB 2.8 the vertex collection would have to exist first.