Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique value in neo4j Nodes

Tags:

neo4j

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 )?

like image 893
Moein Hosseini Avatar asked Oct 22 '12 23:10

Moein Hosseini


1 Answers

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:

  • http://api.neo4j.org/1.8/org/neo4j/graphdb/index/Index.html#putIfAbsent(T, java.lang.String, java.lang.Object)
  • http://api.neo4j.org/1.8/org/neo4j/graphdb/index/UniqueFactory.html

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:

  • http://docs.neo4j.org/chunked/milestone/rest-api-unique-indexes.html

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

like image 98
Nigel Small Avatar answered Nov 01 '22 21:11

Nigel Small