Hello,
I have 2 different JSON files but with a common field in the 2 files. I would like to create a node with properties coming from the 2 files.
how can i do this please?
Now assuming that you've done that, there are different ways to do what you described but this is the easiest:
CALL apoc.load.json("F1.json") YIELD value
UNWIND value.nodes AS node
WITH node
MERGE (u:User {id: node.id})
SET u.name=node.name, u.capacity=node.capacity
WITH "1" as t
CALL apoc.load.json("F2.json") YIELD value
UNWIND value.nodes AS node
WITH node
MERGE (u:User {id: node.id})
SET u.status=node.status
I need a WITH before loading the second json file and that's why I added that arbitrary WITH "1" as t.
MERGE has the ON CREATE and ON MATCH options to set properties only when a new node gets created or it is just matched with an existing node. So feel free to use them to make your cypher more efficient. For example, if you know that name and capacity of a user do not change, then you can replace the first MERGE with this:
MERGE (u:User {id: node.id})
ON CREATE SET u.name=node.name, u.capacity=node.capacity
or if you know that no new node gets created by the second json file, you can replace the second MERGE with this:
MATCH (u:User {id: node.id})
SET u.status=node.status
Thank you so much Sayed Hossein. it's so kind of you to find a solution to my question.
I will try your suggestion and will say you if that works.
by the way, i'm persian too and living in Paris (Damet garm) :)
can i contact you when i have others questions about neo4j ? I have been learning this database for 2 weeks.