Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-26-2020 03:30 AM
Hello, everyone
I'm trying to create relationships between the existing Node by JsonList.
MATCH (n:Recipe) WHERE n.id >5000 AND n.id<5040
WITH apoc.convert.fromJsonList(n.formula) AS datas, n
FOREACH (data in datas|
MERGE (:Scent{name:data.scent})-[:addDrop{drops:data.drops}]->(:Recipe{id:n.id}))
the Recipe( about n.formula) Json format is like below:
{....,
"createdAt": "2017-04-09T05:37:12",
**"formula": "[{"scent":"B9","drops":"1","color":"#E5127F"},{"scent":"M18","drops":"2","color":"#62B86A"},{"scent":"T24","drops":"5","color":"#F07736"},{"scent":"T44","drops":"3","color":"#84825E"},{"scent":"MA51","drops":"2","color":"#E86FA2"},{"scent":"BA69","drops":"3","color":"#84825E"}]"**,
"id": 5001,
....
}
After I run this sctipt, I got the error :
Neo.ClientError.Schema.ConstraintValidationFailed
Node(154918) already exists with label Recipe
and property id
= 5001
How should I create the relationship to the existing node by specific property of the node (by id)?
03-27-2020 10:33 AM
Hi Vivek,
Thanks a lot, I will try it.
03-28-2020 06:24 AM
I found I should MATCH existing node(:Recipe{id:n.id}) first, and then to connect the relationship inside FOREACH loop.
MATCH (n:Recipe) WHERE n.id >5000 AND n.id<5040
WITH apoc.convert.fromJsonList(n.formula) AS datas, n
MATCH (q:Recipe{id:n.id})
FOREACH (data in datas|
MERGE (:Scent{name:data.scent})-[:addDrop{drops:data.drops}]->(q))
Thanks!
All the sessions of the conference are now available online