Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-17-2020 12:08 PM
Is there any way in Aura to set the config option:
cypher.lenient_create_relationship = true
In Aura?
Solved! Go to Solution.
06-05-2020 09:08 AM
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
05-18-2020 07:44 AM
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
05-18-2020 02:32 PM
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
05-18-2020 03:20 PM
Hi Mike,
Can you share an example of your code that's depending on this? And what errors you're getting?
Cory
05-18-2020 04:05 PM
neobolt.exceptions.DatabaseError: Failed to create relationship
UNNAMED407
, nodel
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.
05-19-2020 08:31 AM
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
05-19-2020 09:08 AM
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.
05-19-2020 09:10 AM
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
05-19-2020 09:20 AM
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.
06-05-2020 09:08 AM
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
All the sessions of the conference are now available online