I need to ensure that a combination of more than one property values in all nodes is unique. How to do that in Neo4J.
From Neo4J documentation available at http://docs.neo4j.org/chunked/milestone/transactions-unique-nodes.html, it's possible to ensure uniqueness of one property. But what about combination of 2 or more.
You could try
public Node getOrCreateUserWithUniqueFactory(final String firstName, final String lastname, GraphDatabaseService graphDb) {
UniqueFactory<Node> factory = new UniqueFactory.UniqueNodeFactory(graphDb, "users") {
@Override
protected void initialize(Node created, Map<String, Object> properties) {
created.setProperty("id", properties.get("id"));
created.setProperty("firstName", firstName);
created.setProperty("lastName", lastname);
}
};
return factory.getOrCreate("id", firstName + "_" + lastname);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With