I intend to have multiple organizations existing within my database.
Within a given organization, I'd like to enforce a uniqueness constraint on a node.
For example:
- ✅ Organization 1 creates a
ThingwithnameofABC(OK) - ✅ Organization 2 creates a
ThingwithnameofABC(OK) - ❌ Organization 1 creates a
ThingwithnameofABC- (fails due to uniqueness constraint)
I'm aware that I can add a uniqueness constraint on the name property of the thing label, but it seems that this would be a global constraint across all labels. Which would be fine if my tenant strategy was multi-database, but as of now it is not.
I'm looking to do something like the following (which isn't currently possible):
CREATE CONSTRAINT thing_name_unique_to_org FOR (o:Organization)-[r]->(t:Thing) REQUIRE t.name IS UNIQUE
Is there a way to create this constraint at the Neo4j level, or should I plan to enforce this in code?
You can't do it like this:
But you can try a workaround like this, using
Node Key Constraints, provided you are usingNeo4j Enterprise Edition.You can store the
Organizationunique identifier, in theThingnode, let's sayorgId. Then you can create a constraint like this:This will ensure that
orgIdandnamecombination is unique.