cancel
Showing results for 
Search instead for 
Did you mean: 

Update relations when updating data

javi_xeneize
Node Link

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

2 REPLIES 2

tard_gabriel
Ninja
Ninja

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

javi_xeneize
Node Link

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 🙂

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.