Smart Graph Management
Also SmartGraphs require edge relations to be created, the format of the relations is identical.The only difference is that all collections used within the relations to create a new SmartGraph cannot exist yet. They have to be created by the Graph in order to enforce the correct sharding.
Create a graph
The creation of a graph requires the name and some SmartGraph options.Due to the API edgeDefinitions
and orphanCollections
have to be given, butboth can be empty arrays and can be created later.The can be created using the convenience method _relation
known from the general-graph
module, which is also available here. again is just a list of additional vertex collections which are not yet connected via edges but should follow the same sharding to be connected later on.All collections used within the creation process are newly created.The process will fail if one of them already exists.All newly created collections will immediately be dropped again in the failed case.
- edgeDefinitions (required) List of relation definition objects, may be empty
- orphanCollections (required) List of additional vertex collection names, may be empty
- smartOptions (required) A JSON object having the following keys:
- smartGraphAttribute (required)The attribute that will be used for sharding. All vertices are required to have this attribute set and it has to be a string. Edges derive the attribute from their connected vertices.Examples
Create an empty graph, edge definitions can be added at runtime:
Create a graph using an edge collection edges
and a single vertex collection vertices
Create a graph with edge definitions and orphan collections:
Modify a graph definition at runtime
After you have created a SmartGraph its definition is also not immutable.You can still add or remove relations.This is again identical to General Graphs.However there is one important difference:You can only add collections that either do not exist, or that have been created by this graph earlier.The later can be achieved if you for example remove an orphan collection from this graph, without dropping the collection itself.Than after some time you decide to add it again, it can be used.This is because the enforced sharding is still applied to this vertex collection, hence it is suitable to be added again.
In most cases this function works identically to the General Graph one.But there is one special case:The first vertex collection added to the graph (either orphan or within a relation) defines the sharding for all collections within the graph.This collection can never be removed from the graph.
Parameters
- vertexCollectionName (required) Name of vertex collection.
- dropCollection (optional) If true the collection will be dropped if it isnot used in any other graph. Default: false.Examples
The following example shows that you cannot drop the initial collection.You have to drop the complete graph.If you just want to get rid of the data truncate
it.