Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-10-2021 11:30 AM
Hi
I would like to know what is the best way to update data and the relations in the database. Let me explain
I am ingesting data using APOC. At some point, my DB is like this
A1->B
A2->B
A3->B
B->C1
B->C2
B->C3
I want to update B, so it has a relation now with C1 and C2, and no longer with C3.
What is the best way to do it, just update the relations, delete C3, or re-insert B and create only the new relations (B->C1 and B->C2)?
Thanks
04-11-2021 10:32 AM
I'm sure I get want you want:
MATCH (B)-[r]->(C)
DELETE r
Is the over general way to go for your use case but there is a lot of information missing
04-11-2021 11:09 AM
Thanks for the answer. Let me add more info with an example:
I have a relation within houses and people living in the house. After ingesting the initial set of data my graph is as follows (the relation is OCCUPIED_BY):
Red_house->John
Red_house->Max
White_house->Anthony
White_house->Paul
The JSON used to add this is {red_house: [John, Max], white_house: [Anthony, Paul]}
Now, imagine that Max has left the house, Paul moves to the red house, and James moves to the white house. I will ingest now the following JSON to reflect that situation
{red_house: [John, Paul], white_house: [Anthony, James]}
So, my graph now needs to look like this:
Red_house->John
Red_house->Paul
White_house->Anthony
White_house->James
With this in hand, what is the best option to reach that picture from the initial one? I was planning to check if the data to be ingested exists, and if so, update the relations accordingly, (remove the unneeded relations and create the new ones). If the data doesnt exist, just do a normal ingestion, but I dont know if there is an easier way of doing it
Hope it helps to understand my question
Thanks 🙂
All the sessions of the conference are now available online