Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-20-2018 06:31 AM
Hi guys! I need some help with a operation in Neo4j.
I have a relation like (c)-[a]->(u)-[v]->(p).
Actualy i have a query return return c, u, COLLECT(v), p ... I made this logical to isolate [v] (Visit) and preserve a perspective to single result for c, u and p, and get a set of [v].
BUT, in this same query, I need to put some restrictions with WHERE using the COLLECT(v).
My doubt is:
Thank's guys!
12-20-2018 08:34 AM
If you need to filter the v
relationships, do so before the collection.
...
WITH DISTINCT c, u, v, p
WHERE <predicate to filter v relationships>
WITH c, u, p, collect(v) as rels
...
Otherwise, you can collect and apply a filter() operation (though I prefer list comprehension):
WITH c, u, p, collect(DISTINCT v) as rels
WITH c, u, p, [rel in rels WHERE <predicate for rel>] as rels
...
12-21-2018 06:05 AM
Thank's Andrew, I forgot to mention the need to use a restriction by SIZE, using your example:
WHERE rels = [some integer value]
WITH c, u, p, collect(DISTINCT v) as rels
I know that query structure will never work, but that's the dilemma.
Otherwise, thanks Andrew, if you have another tip I apreciate!
😃
12-21-2018 09:02 AM
Andrew, thanks buddy you solved my problem. I use the second option that you gaved me.
WITH c, u, p, [rel in rels WHERE <predicate for rel>] as rels
It works fine.
Thank you so much!!
All the sessions of the conference are now available online