Reputation: 711
I have two column in csv file, emp_id
and mngr_id
. The relationship is (emp_id)-[:WORKS_UNDER]->(mngr_id)
. I want to merge all those nodes where emp_id=mngr_id. How to do that while creating nodes itself?
Upvotes: 0
Views: 314
Reputation: 1707
If I understand correctly, you're looking to ensure that you avoid creating duplicate relationships when iterating over the CSV data and avoid entering a relationship where a person works for themselves.
To avoid creating a relationship where emp_id
and mngr_id
identify the same person, I would suggest filtering the CSV before processing it to enter the data. It should be much easier to omit any lines in the CSV file where the emp_id
and mngr_id
are the same value before passing it to Neo4j.
Next, if you're using Cypher to do the importing, something like this may be useful:
MERGE (emp:Person{id:'emp_id'}) MERGE (mgr:Person{id:'mngr_id'}) MERGE (emp)-[:WORKS_UNDER]->(mgr) RETURN emp,mgr
Note that if you run the above query multiple times in a block statement then you'll need unique identifiers for emp
and mgr
in each query.
Merge is explained well in the Neo4j docs: http://docs.neo4j.org/chunked/stable/query-merge.html
Upvotes: 1