I'm making an application which use neo4j as my back-end db. I have this class :
class Person
{
public string Id{get;set;}
public string Name{get;set;}
}
I want to create a query that return 0 when person.Id exists in db (that means there can't be users with the same id exist in db together) and 1 when person.Id doesn't exist.
Can anyone help me please ?
Thank you,
P/S:
Neo4jClient or Neo4j query is OK .
I can convert Neo4j query to Neo4jClient in .Net
You can use combination of OPTIONAL MATCH
and CASE
:
OPTIONAL MATCH (P:Person {Id:123})
RETURN CASE P WHEN NULL THEN 1 ELSE 0 END
CREATE CONSTRAINT ON (P:Person) ASSERT P.Id IS UNIQUE