Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-21-2021 11:33 AM
I have a "messy" data source that has duplicates in it, and trying to process it cleanly into Neo4j.
Imagine the following graph:
MATCH (cmk:Make)-[r:hasModel]->(cmm:Model) RETURN cmk,r,cmm
I tried using MERGE but I guess it's for node properties only. How do I ensure that I don't have the r:hasModel
relationship is present between two nodes exactly 0 or 1 times? In other words, I have created makes, and models, and when I process the relationships, sometimes I hit a duplicate and was looking for a single cypher that will create the r:hasModel
relationship only if it doesn't already exist, between two target nodes.
I tried CREATE UNIQUE
but it seems to kill my connection to Neo4j!
Thanks!
08-21-2021 03:40 PM
You can actually use MERGE
on relationships as well. Things can be tricky sometimes though if you are trying to MERGE
nodes and relationships simultaneously. Depending on the type of sources you are using, I generally like to break down node creation and relationship creating into separate steps to keep things simple and "modular".
All the sessions of the conference are now available online