2

I am trying to create unique constrain using accepted answer found at: Neo4jClient - Create index from within Neo4jClient?

I am using Neo4jClient v1.1.0.11

The example is:

graphClient.Cypher
    .CreateUniqueConstraint("identity", "property")
    .ExecuteWithoutResults();

The problem is that when I execute this example I receive this exception:

SyntaxException: Invalid input ')': expected an identifier character, whitespace or NodeLabel (line 1, column 31 (offset: 30)) "CREATE CONSTRAINT ON (identity) ASSERT property IS UNIQUE" ^

When I use this statement:

client.Cypher
    .Create("CREATE CONSTRAINT ON (c:User)ASSERT c.UserId IS UNIQUE")
    .ExecuteWithoutResults();

I receive this error:

SyntaxException: Invalid input 'O': expected 'r/R' (line 1, column 16 (offset: 15)) "CREATE CREATE CONSTRAINT ON (c:User)ASSERT c.UserId IS UNIQUE" ^

My question is what is the correct way of creating unique index using Neo4JClient? An example would be appreciated.

Thanks

Community
  • 1
  • 1
huber.duber
  • 762
  • 2
  • 7
  • 31

1 Answers1

5

In your first code snippet you are not specifying what you are trying to create the constraint on. Add the identifier, label and property as follows

graphClient.Cypher
    .CreateUniqueConstraint("c:User", "c.UserId")
    .ExecuteWithoutResults();

Your second snippet is merely adding create twice. Maybe this could be fixed like so

graphClient.Cypher
    .Create("CONSTRAINT ON (c:User) ASSERT c.UserId IS UNIQUE")
    .ExecuteWithoutResults();

Although I would recommend the first approach...

ceej
  • 1,863
  • 1
  • 15
  • 24
  • Additional question: Can you please tell the C# way of this statement: client.Cypher.Create("INDEX ON :User(FullName)").ExecuteWithoutResults(); – huber.duber Oct 29 '15 at 23:45
  • @huber.duber That's the way I'd go about doing it, there's no specific entry point for creating indexes as there is for unique constraint. If you want it - feel free to add as an issue on the `Neo4jClient` github page, and I can look into it - or you could do a pull request if you want - all are gladly accepted :) – Charlotte Skardon Oct 30 '15 at 09:33
  • Thanks, will try that – huber.duber Oct 30 '15 at 18:34