Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-16-2022 05:53 AM
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
08-16-2022 06:17 AM
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
08-16-2022 07:25 AM - edited 08-16-2022 07:27 AM
--duplicate--
08-16-2022 07:26 AM
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.
All the sessions of the conference are now available online