cancel
Showing results for 
Search instead for 
Did you mean: 

Can you set cypher.lenient_create_relationship = true in Aura

mike2
Node Clone

Is there any way in Aura to set the config option:
cypher.lenient_create_relationship = true
In Aura?

1 ACCEPTED SOLUTION

luke_gannon
Neo4j
Neo4j

Hi @mike2,

The best thing to do with cypher is to use the case when for each hack (and a bit of moving around to your original query). Below is how I tested it:

Set up some params in the browser:

:param authorId => 1;
:param event: { foo: 'foo', bar: 'bar',  uid: 1 } ;
:param locationId => 1;
:param startDateId => 1234;
:param endDateId => 2345;

Created a user:

CREATE (u:User {user_id: $authorId})

With nothing in the DB, the first time around we're only going to get the Author relationship between a user and an Event.

OPTIONAL MATCH (l:Location{uid: $locationId})
OPTIONAL MATCH (start:Dates{uid: $startDateId})
OPTIONAL MATCH (end:Dates{uid: $endDateId})
WITH *
MATCH (u:User{user_id: $authorId})
MERGE (e:Event{uid: $event.uid})
ON CREATE SET e = $event
MERGE (e)-[:AUTHOR]->(u)
FOREACH (_ IN CASE WHEN l IS NOT NULL THEN [1] END | MERGE (e)-[:WHERE]->(l))
FOREACH (_ IN CASE WHEN start IS NOT NULL THEN [1] END | MERGE (e)-[:START]->(start))
FOREACH (_ IN CASE WHEN end IS NOT NULL THEN [1] END | MERGE (e)-[:END]->(end))

Now I can load another node in:

CREATE (l:Location {uid: 1, foobar: 'foobar'})

Give it a go and hopefully that solves your problem.

Cheers,
LG

View solution in original post

9 REPLIES 9

cory_waddingham
Graph Buddy

Hi Mike,

Thanks for your interest in Neo4j Aura.

Something to keep in mind with Aura is that we've designed it to be as quick and simple as possible to get a Neo4j database up and running. By clicking a few buttons you can have a graph database with fault tolerance and high availability in only a few minutes.

Part of making that work consistently, though, means using the same configuration settings for each new database. So, editing the neo4j.conf file for your Aura database is not available. Which of course means that there is not a way to enable custom settings or change the ones that are set.

Cory

Hey Cory,

Thanks for the quick reply.

I wrote all my code so far assuming the lenient_create_relationship would be set to true.

Is there any good examples of how to make code that makes that assumption work with out it?

I believe the issue only comes up in my Merge Statements throughout the code.

It may be a good idea to make it very obvious in the documentation things that Aura can't do (I am sure it's there somewhere, but obviously not where I looked which was looking for how to fix errors related to creating relationships.)

Thanks,

Mike

Hi Mike,

Can you share an example of your code that's depending on this? And what errors you're getting?

Cory

mike2
Node Clone

neobolt.exceptions.DatabaseError: Failed to create relationship UNNAMED407, node l is missing. If you prefer to simply ignore rows where a relationship node is missing, set 'cypher.lenient_create_relationship = true' in neo4j.conf

 MATCH (u:User{user_id: $author_id})
 MERGE (e:Event{uid: $event.uid})
 ON CREATE SET e = $event
 MERGE (e)-[:AUTHOR]->(u)
 WITH e
     OPTIONAL MATCH (l:Location{uid: $location_id})
     OPTIONAL MATCH (start:Dates{uid: $start_date_id})
     OPTIONAL MATCH (end:Dates{uid: $end_date_id})
     MERGE (e)-[:WHERE]->(l)
     MERGE (e)-[:START]->(start)
     MERGE (e)-[:END]->(end)

This comes from my Python script that imports the data from my old Postgres version of my code into the Neo4j instance. I have similar code on the code that adds nodes and relationships throughout the rest of the application code.

Hi Mike,

Sorry for the delay, this response came in late in the day for me yesterday.

Rather than using OPTIONAL MATCH you could break up your merges using WITH, so that each merge is its own subquery. If one fails it won't stop the others from proceeding. For instance:

MATCH (u:User{user_id: $author_id})
 MERGE (e:Event{uid: $event.uid})
 ON CREATE SET e = $event
 MERGE (e)-[:AUTHOR]->(u)
 WITH e
     MATCH (l:Location{uid: $location_id})
     MERGE (e)-[:WHERE]->(l)
 WITH e
     MATCH (start:Dates{uid: $start_date_id})
     MERGE (e)-[:START]->(start)
 WITH e
     MATCH (end:Dates{uid: $end_date_id})
     MERGE (e)-[:END]->(end)
 return e

Cory

mike2
Node Clone

Cory,

That solved the issue.

Since there is an easy alternate way to implement lenient relationships, it may be a good idea to deprecate and eventually remove that setting so as not to cause confusion. I could see lot's of places where having that set and someone not realizing it was set could cause confusion to people.

Hi Mike,

That's a good suggestion, I'll pass it on to our engineering team. We're always looking for feedback from users on how to improve the product.

Cory

So, I tried putting it in some other places, it looks like if one of the MATCHes inside the WITH doesn't MATCH it is not processing the rest of the query, it seems to be stopping on the last successful match.

Which is what I though the difference between OPTIONAL MATCH and MATCH was, but of course if a switch it back to OPTIONAL MATCH then I start getting the lenient error again

I am pretty sure I can fix it using call apoc.do.when, which I had to use in some places where I have lists of things to merge, but that's going to make the code a lot harder to read.

luke_gannon
Neo4j
Neo4j

Hi @mike2,

The best thing to do with cypher is to use the case when for each hack (and a bit of moving around to your original query). Below is how I tested it:

Set up some params in the browser:

:param authorId => 1;
:param event: { foo: 'foo', bar: 'bar',  uid: 1 } ;
:param locationId => 1;
:param startDateId => 1234;
:param endDateId => 2345;

Created a user:

CREATE (u:User {user_id: $authorId})

With nothing in the DB, the first time around we're only going to get the Author relationship between a user and an Event.

OPTIONAL MATCH (l:Location{uid: $locationId})
OPTIONAL MATCH (start:Dates{uid: $startDateId})
OPTIONAL MATCH (end:Dates{uid: $endDateId})
WITH *
MATCH (u:User{user_id: $authorId})
MERGE (e:Event{uid: $event.uid})
ON CREATE SET e = $event
MERGE (e)-[:AUTHOR]->(u)
FOREACH (_ IN CASE WHEN l IS NOT NULL THEN [1] END | MERGE (e)-[:WHERE]->(l))
FOREACH (_ IN CASE WHEN start IS NOT NULL THEN [1] END | MERGE (e)-[:START]->(start))
FOREACH (_ IN CASE WHEN end IS NOT NULL THEN [1] END | MERGE (e)-[:END]->(end))

Now I can load another node in:

CREATE (l:Location {uid: 1, foobar: 'foobar'})

Give it a go and hopefully that solves your problem.

Cheers,
LG