MichaelE
MichaelE

Reputation: 767

Create Unique record in Neo4j regardless of identifier label

I would like to create a set of three nodes, each set have a different label:

Create (n: label1 {email:"[email protected]"})
Create (n: label2 {email:"[email protected]"})
Create (n: label3 {email:"[email protected]"})

where the email is unique across all nodes.

  Create Constraint On (n:label {email:"[email protected]"}) Assert n.email IS Unique

Only create uniqueness for each label/email combination. Can anyone say if there is a way to get the email unique across all nodes.

Correction to constraint query:

Create Constraint On (n:label) Assert n.email IS Unique

the one above is incorrect.

Upvotes: 0

Views: 99

Answers (1)

Frank Pavageau
Frank Pavageau

Reputation: 11705

You can set a secondary label on all nodes which have an email property, and set the constraint on that one:

CREATE (n:label1:WithEmail {email:"[email protected]"})

and

CREATE CONSTRAINT ON (n:WithEmail) ASSERT n.email IS UNIQUE

Upvotes: 2

Related Questions