stack overflow community i am relatively new for arango and wants to build an AQL query using two collection please help me
first collection:- user JSON:- "user_id": "abcd", "program_info": [ { "program_id": 101, } ]
Second collection:- program JSON:- { "program_id":101, "program_name": "test" }
i am building query to get info of program name using both collection if user_id will supplied FOR u IN user FILTER u.user_id =="abcd" FOR p IN program FILTER p.program_id == u.program_info[*].program_id RETURN p.program_name
but i am getting blank [] array please help me
The expression u.program_info[*].program_id
returns an array with all program_id
attributes from the objects in the program_info
array. However, you are comparing this array with the scalar value p.program_id
which does match and therefore you get an empty array. I suppose you want to check if p.program_id
is contained in user's program_info
. That could be done like this:
FOR u IN user
FILTER u.user_id =="abcd"
FOR p IN program
FILTER p.program_id IN u.program_info[*].program_id
RETURN p.program_name
However, for better index usability it might even be better to rewrite your query like this (provided you have an index on program_id
for the program
collection):
FOR u IN user
FILTER u.user_id =="abcd"
FOR pid IN u.program_info[*].program_id
FOR p in program
FILTER p.program_id == pid
RETURN p.program_name
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.