cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

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.