β08-01-2022 02:08 AM
Hi All,
I am trying to create a new node based on the common property found in the existing nodes. Say for example, I have two nodes Car1 and Car2. Both have the same property color:'blue'. Now I want to create a new node called Color and create a relationship between the Cars and the Color.
I am running the below query to achieve the same but I getting the memory error.
Solved! Go to Solution.
β08-01-2022 04:37 AM - edited β08-01-2022 04:38 AM
Is your βcolorβ property really an array, as you are unwinding it? I will provide solutions for both an array and not an array.
You can approach it the way you did by collecting all cars by color and processing each color in full, but this will require a lot of memory if the database is not small. Instead, I suggest processing each car one-by-one.
β08-01-2022 04:31 AM
Hello @HaribaskarS π
This query should solve your issue (you will need APOC plugin):
CALL apoc.periodic.iterate("
MATCH (c:Car) RETURN c
", "
MERGE (c)-[:GROUP_TYPE]->(:Color {car_color: c.color)
", {batchSize: 10000, parallel:true}
)
Regards,
Cobra
β08-01-2022 04:37 AM - edited β08-01-2022 04:38 AM
Is your βcolorβ property really an array, as you are unwinding it? I will provide solutions for both an array and not an array.
You can approach it the way you did by collecting all cars by color and processing each color in full, but this will require a lot of memory if the database is not small. Instead, I suggest processing each car one-by-one.
β08-01-2022 05:32 AM
Thanks a lot!! that works
β08-01-2022 04:52 AM
Thanks for the reply Cobra,
The query which you mentioned is creating a new Color node for each of the car nodes. I just want to create distinct color nodes so that all the car nodes that have the same color will point to a single color node.
All the sessions of the conference are now available online