Reputation: 687
Is a simple query, but i don't know which cypher operation or java collection would be useful to get the expected result.
So, again working with users assigned to a specific Taxi, where each user has a Grid destination (drop off).
First i returned the users assigned to a specific Taxi and same dropOff time:
MATCH (g:Grid)<-[d:DROP_OFF]-(u:User)-[rt:ASSIGNED]->(t:Taxi {name: 'Taxi1813'})
WHERE d.time = '04:38'
RETURN u.name, g.name as LocationGrid
u.name LocationGrid
UserTestSame Grid1239
UserTestNew Grid919
User177 Grid1239
I would like to add a condition to return the users located in the same Grid. The result set is not fixed; i may have n number f users.
Is there an easy way to do that, or should i use a collection in java to compare each Grid.
Thank you in advance
Upvotes: 0
Views: 53
Reputation: 141
//just use the answer above me Also Neo4j has an option to use collect so the results come back in a list.
Match(n)-[]->(r) return n, collect (r) as collection
http://neo4j.com/docs/stable/query-aggregation.html#aggregation-collect
I think you should change your date time. Not in a string but more like yyyyMMddhhmmss so you can compare. Or any other way.
It would also be faster not to store it as a string.
Upvotes: 1
Reputation: 1949
You can use aggregate Cypher's built-in aggregate functions, such as collect
:
MATCH (g:Grid)<-[d:DROP_OFF]-(u:User)-[rt:ASSIGNED]->(t:Taxi {name: 'Taxi1813'})
WHERE d.time = '04:38'
RETURN g.name as LocationGrid, collect (u.name) as users
LocationGrid users
Grid1239 [UserTestSame, User177]
Grid919 [UserTestNew]
Your query assumes that users assigned to the same taxi have the same drop off time? Seems confusing to me, but I might be missing something.
BTW, I don't think storing and matching the drop off time as a string is going to be very suitable for following reasons:
I'd recommend modelling the drop off time as a time tree. See following links for reference:
Upvotes: 1