Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-15-2020 10:50 PM
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.
Solved! Go to Solution.
07-15-2020 11:52 PM
No I mean do you use something like:
UNWIND $row1 AS row1
UNWIND $row2 AS row2
07-15-2020 11:01 PM
Hello @tarendran.vivekanand
You can get the size of your collection before to UNWIND
Are you using parameters for your request and if yes, could you show us its version?
Moreover what is the a
in the WITH
? Did you try to remove it?
Regards,
Cobra
07-15-2020 11:25 PM
Hi @Cobra
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
07-15-2020 11:30 PM
What is a
in WITH collect(row1) as combine, a
?
07-15-2020 11:35 PM
sorry meant to use c, edited my comment
07-15-2020 11:39 PM
What does return
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
07-15-2020 11:42 PM
It returns combine
by separating it into 3
07-15-2020 11:44 PM
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:)
07-15-2020 11:50 PM
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))
😞
07-15-2020 11:52 PM
No I mean do you use something like:
UNWIND $row1 AS row1
UNWIND $row2 AS row2
07-15-2020 11:59 PM
I finally got what u meant
Thanks @Cobra
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
07-16-2020 12:01 AM
Does it works?
07-16-2020 12:29 AM
Yea when i used the above query. Thanks
All the sessions of the conference are now available online