cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

unique property

OmarHamdy
Node Clone

I am trying to create node but with unique specific property to get the node by this property , knowing that this property is the name in my project nodes , please anyone explains how neo4j handles the uniqueness 

3 REPLIES 3

I recommend that you go through our newest course which teaches about uniqueness constraints in Neo4j.

https://graphacademy.neo4j.com/courses/cypher-indexes-constraints/

Elaine

apankraz
Node Link

--duplicate-- 

apankraz
Node Link

Hi Omar, you can create a uniqueness constraint in your graph, which dictates that a specific property on a specific label will have a unique value in your graph. 

 

 

CREATE CONSTRAINT YourUniqueConstraint IF NOT EXISTS
FOR (x:YourLabel)
REQUIRE x.name IS UNIQUE

 

 

 With this you would be able to create a node (:YourLabel {name: 'myname'}) once, if another node with the label :YourLabel and the value 'myname' tries to get created, neo4j will reject this attempt and throw an error.

 

Furthermore adding the constraint is automatically creating an index for this label and property, so finding a node with a specified name will be able to use an index for faster lookup.