cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Struggling to update a list

bill_dickenson
Graph Buddy

I have a list of with 5 elements ["normal", "normal", "normal", "1","3"] attached to the node as dElement. I access these by index as you would expect dElement[1]

But I have a condition where I will need to change one of the elements based on a match/where combination. What I am looking for apparently is the APOC equivalent of match (a {hash:'changed'}) set dElement[1] = 'abbynormal'

If I read this correctly I am going to remove the element ( apoc.coll.remove(dElement,1,1)) then insert an element apoc.coll.insertAll(dElement,1,'abbynormal') but I cannot seem to come up with the syntax that works. The combination of match and two apoc calls is defeating me.

3 REPLIES 3

ameyasoft
Graph Maven
Try this:

with  ["normal", "normal", "normal", "1","3"] as d1
return apoc.coll.set(d1, 1, 'abbynormal') AS d2

Result:
["normal", "abbynormal", "normal", "1", "3"]

That would work except that I have no way to know what the rest of the list is and its been set already. When the program runs through, it sets them all to the default. As each condition is evaluated, it updates the appropriate flag in the list.When all 5 are run, the result (dElement) is passed. So on any given node, I don't know what the other 4 flags are. Otherwise I might have just used one flag.

So each of these is being set independently. I can ONLY afford to update the one. The others may have been updated by another set. The issue here is we can only pass one variable and it has to be a list. we are evaluating 5 separate conditions.

Would this work ?

with dElement as d1 return apoc.coll.set(d1,1,'abbynormal') as d2

and then update dElement = d2 ?

Thanks

This worked. Not overly clever, but it worked. It allowed me to update [1] without changing or knowing [0] or [2]. I think this is what Ameysoft was suggesting, I just didn't get it.

match (a) where a.display = false set a.dElement= [a.dElemenet[0],'Octagon',a.dElement[2]] return count(a)

That allowed me to update just one element in the list. Not as elegant as dElement[1] = 'Octagon' but close

Thanks