Hi all,
I am trying to get the size of function collect so that I can use it later as a condition for apoc.do.case but I return (1,1,1). I understand it has to do with the WITH clause but im not sure why this is the case.
UNWIND [{name:'test1'},{name:'test2'},{name:'test3'}] AS row1
UNWIND [{Type:'Sports car'}] AS row2
MATCH (c:Car {name:row1.name})
SET c += row2
WITH collect(row1) as combine, c
RETURN size(combine)
Intended results is size(combine) = 3
Thanks in advance.
My query is as such as im going to perform an apoc.do.when later (shown below).
Thus, even if I place the size before I have the same problem.
UNWIND [{name:'test1'},{name:'test2'},{name:'test3'}] AS row1
UNWIND [{Type:'Sports car'}] AS row2
MATCH (c:Car {name:row1.name})
SET c += row2
WITH collect(row1) as combine, c
CALL apoc.do.when(
size(combine) > 1,
'MATCH (d:Driver {name:"User1"})
MERGE (d)-[:USES]->(c)
RETURN c',
'RETURN NULL',
{c:c,combine:combine}) YIELD value
RETURN value
UNWIND [{name:'test1'},{name:'test2'},{name:'test3'}] AS row1
UNWIND [{Type:'Sports car'}] AS row2
MATCH (c:Car {name:row1.name})
SET c += row2
RETURN collect(row1) as combine, c
So your collect is useless, it's because of the c, if you don't return the c, it should be only one list. Are you using arguements in your request? Because you could directly return the size of the argument:)
Yes i am using c later in the apoc.do.when. Even if I place the match inside the apoc.do.when, I cant use the collect function in the apoc.do.when: size(collect(row1)) :(
UNWIND $test AS row1
UNWIND [{Type:'Sports car'}] AS row2
MATCH (c:Car {name:row1.name})
SET c += row2
WITH c
CALL apoc.do.when(
size($test) > 1,
'MATCH (d:Driver {name:"User1"})
MERGE (d)-[:USES]->(c)
RETURN c',
'RETURN NULL',
{c:c,test:$test}) YIELD value
RETURN value