Is it possible to limit the multiplicity of edges in Neo4j / OrientDB?

I was wondering if Neo4j and OrientDB provide the ability to define constraints in terms of multiplicity for specific edge types?

+6
source share
2 answers

For OrientDB

You can set the multiplicity in the output / in the collection to the label. Example of setting the maximum 1 edge from Person to the company if the red label is "workFor":

ALTER PROPERTY Person.out_workFor NOT NULL ALTER PROPERTY Person.out_workFor MAX 1 

You can also set a minimum with:

 ALTER PROPERTY Person.out_workFor MIN 1 

Thus, with min and max, he always has one and only one relation to the Company.

+6
source

For Neo4j

What do you want to do when the constraint is violated? Exception and rollback or somehow merge?

For power 1: 1 there is a merger

 MATCH (p:Person {name:"Pablo"}) MATCH (c:Company {name:"Era7"}) MERGE (p)-[:WORKS_FOR]->(c); 

For higher power limits, you can either go with a framework that supports metamodels and a circuit like structr.org or sylvadb .

Or you can set up a small tx event handler that checks your power and throws an exception if you violate the restrictions.

I would like to write a blog post about this, so stay tuned.

-1
source

Source: https://habr.com/ru/post/976478/


All Articles