Marko's solution works, because you roll back the transaction once you find a
duplicate entry.
Another solution to this problem is to use the SortedTree index in
graph-collections https://github.com/peterneubauer/graph-collections, which has
a setting that makes an index unique. This component is relatively new and
could use some proper testing, though.
Niels
> From: e...@nextideapartners.com
> To: user@lists.neo4j.org
> Date: Thu, 7 Jul 2011 10:53:20 -0400
> Subject: Re: [Neo4j] Unique Constaint on Index
>
> How do I ensure another request is not performing the same operation on
> another node in the cluster?
>
>
> -----Original Message-----
> From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On
> Behalf Of Marko Rodriguez
> Sent: Thursday, July 07, 2011 10:35 AM
> To: Neo4j user discussions
> Subject: Re: [Neo4j] Unique Constaint on Index
>
> Hi,
>
> > We are testing Neo4J and need to support unique emails across all
> > users. Is this possible with the current API?
>
> You can add such a constraint when updating the indices:
>
> if(index.get('email', address).hasNext()) {
> throw new RuntimeException("There are two nodes that share the same email
> address."); } else {
> index.put('email', address, node);
> }
>
> Marko.
>
> http://markorodriguez.com
> _______________________________________________
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>
> _______________________________________________
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
_______________________________________________
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user