Reputation: 243
I need to create a unique index across any vertex, irrespective of label, in Neo4j.
I can do the following, but it would not guarantee global uniqueness:
CREATE CONSTRAINT
ON (x:myType1)
ASSERT x.identifier IS UNIQUE
The above would allow (x:myType1) and (y:myType2) to have the same identifier
.
Is there any way I could implement a globally unique uniqueness constraint?
Upvotes: 1
Views: 62
Reputation: 243
There might be better ways, but I just seem to have found one: using another label.
CREATE (v:label1:global {identifier:"12345")
And have the global uniqueness constraint only set against the global label:
CREATE CONSTRAINT ON (g:global) ASSERT g.identifier IS UNIQUE
Upvotes: 1