7

How can I define some value should be unique in Neo4j?

for example think I want to store users data in node,so username should be unique.Is there any way to do it like what we do in sql ( define username as unique properties )?

Moein Hosseini
  • 4,309
  • 15
  • 68
  • 106

1 Answers1

13

For this you will need to use a node index and the uniqueness features available within the API to ensure that only one node is filed under each key-value pair. If you're working with Neo4j embedded then have a look at:

For the REST interface, you may have uniqueness support already in the library that you are using or, if you are not using a library, this page should help:

As node structures are not enforced in the same way that record structures are enforced in most RDBMSs, there is no direct equivalent to the UNIQUE KEY feature that you mention. Index uniqueness should however give you the same end result.

Hope this helps

Nige

Nigel Small
  • 4,475
  • 1
  • 17
  • 15
  • With 2.0 this approach http://docs.neo4j.org/chunked/milestone/tutorials-java-embedded-unique-nodes.html#tutorials-java-embedded-unique-get-or-create is the preferred way to create unique nodes, am I correct? – Tvaroh Dec 05 '13 at 18:55