Hi Neo4j community,
I have now been trying for a while and reading up on unwind, collect, etc and try to achieve something I have no issues with using Python and running a nested for loop. However when I do this I will perform a similar query many, many times and this is super slow eventually where I belive running this as one single query it might be a lot faster.
My situation is the following. I have got a graph database with Employee nodes whose (artificial) name property is
Department_i_Employee_j with i,j flexibel, i.e. I have
Department_0_Employee_1
Department_0_Employee_2
Department_1_Employee_1
and so on. They also have a deparment property which I guess is not relevant for what I want to do.
What I would like to achieve is having two list, one for the a certain set of departments (giving me the i) and one for a certain number of employees (giving me the maximum j for the respective i) in the respective department and I want to update respective nodes.
So say given the lists [0,1,2] and [4,2,6] I would like to update
Department_0_Employee_1
...
Department_0_Employee_4
Department_1_Employee_1
Department_1_Employee_2
Department_2_Employee_1
...
Department_2_Employee_6
As mentioned I eventually like to update them and using a nested for loop in Python and updating each vertex using a separate query works, but takes really long for bigger instances.
I have tried many things using unwind, collect, foreach and just cannot seem to get there, so I would like to do something like this
MATCH (e:Employee)
WITH e.department AS dep, COUNT(*)/5 AS deptSize
UNWIND range(0,2) as depts
UNWIND deptSize as sizes
UNWIND range(1,sizes) AS number
MATCH (e:Employee) WHERE e.name ="Department_"+toString(depts)+"_Employee_"+toString(number)
SET e.newProperty = 'new'
however this for example does nothing at all.
Any help would be much appreciated and I am sure it is not too complicated and the answer is almost there, but have been trying for a while and reading up on it and just don't quite get there.
Thanks a lot for helping