0

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

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.