Reputation: 1
I'm stuck with filtering on aggregated data using ArangoDB
Imagine a graph with user documents. Every user has a number of game consoles. So the graph is
User -[]-> GameConsole
I need a query that lists all users with its game consoles. AND I want to be able to FILTER for all users with a specific game console but the query result still needs to show ALL consoles of the user (if he has more than one)
I took the example for post-filtering aggregated data from the Arango DB docs: https://www.arangodb.com/docs/stable/aql/examples-grouping.html an modified it to my needs:
FOR u IN User
FOR c IN 1..1 OUTBOUND u plays
COLLECT userData = u INTO consoles = c
FILTER "GameConsole/Playstation3" IN consoles
RETURN {userData, consoles}
Expected result
[
{ "userData":
{
"_id": "User/JohnDoe",
"Name": "John Doe"
},
"consoles": [
{
"_id": "GameConsole/Playstation3",
"Name: "Playstation 3"
},
{
"_id": "GameConsole/Wii",
"Name": "Wii"
}
]
}
]
But the result is an empty array:
[
[]
]
Same for
[...]
FILTER consoles == "GameConsole/Playstation3"
FILTER consoles._id == "GameConsole/Playstation3"
FILTER consoles[*]._id == "GameConsole/Playstation3"
What is the correct query/FILTER statement to show all users that own a Playstation3 AND list all consoles they own?
Upvotes: 0
Views: 79
Reputation: 1
I've found a solution. As consoles is an array and I need to filter on attribute (like _id), I need to expand the array when filtering: consoles[*]._id
So the working query is
FOR u IN User
FOR c IN 1..1 OUTBOUND u plays
COLLECT userData = u INTO consoles = c
FILTER "GameConsole/Playstation3" IN consoles[*]._id
RETURN {userData, consoles}
Hope that helps anyone else.
Upvotes: 0