Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-04-2020 11:22 PM
I have the following code
<"MERGE (a:Person{id: abc.id}) MERGE (b:Place{id:def.id}) MERGE (c:event{id:abcd.id}) MERGE (a)–[:was_at]->(b) MERGE (a)–[:is]->(c) MERGE (c)–[:took_place_at]->(b)">
I wish to create the node a only if the id does not already exist in the database. How can I do so? Do i make use of apoc?
10-04-2020 11:45 PM
Hello @james.irvin and welcome to the Neo4j community
MERGE
is the right keyword to create if it doesn't exist, what is the issue with your query?
Regards,
Cobra
10-04-2020 11:48 PM
I tried the following but it threw this error. I wish to only create a new person node if there isnt a person node in the existing database that has the exact same properties.
org.neo4j.driver.exceptions.ClientException: Invalid input 'R': expected
MERGE (n:Person{id: abc.id})
MERGE (m:Place{place:def.id})
MERGE (o:Thing{id:abcd.id})
WITH n,m,o
OPTIONAL MATCH (n) – [:present_at] -> x with n,m,o, collect (distinct x) as known_place
OPTIONAL MATCH (m) – [:is] -> y with n,m,o, collect (distinct y) as known_thing
FOREACH (a in ( CASE WHEN NOT m IN known_place THEN [1] ELSE [] END ) CREATE (n)-[:present_at] ->(m))
FOREACH (a in ( CASE WHEN NOT o IN known_thing THEN [1] ELSE [] END ) CREATE (m)-[:is] ->(o))
All the sessions of the conference are now available online