Hi,
I am confused with all the possible options (NEST, JOIN, ARRAY_AGG) offered by N1QL.
Should be a very common use case but now I cannot figure out which way to go. I could only do one level of nesting using NEST and ON KEY Thank you for your help.
Here is my data, all in one bucket:
{'type':'company', 'name':'company A'}, {'type':'company', 'name':'company B'}, ... {'type':'department', 'name':'department 1', 'company_id':'company_A_id'}, {'type':'department', 'name':'department 2', 'company_id':'company_A_id'}, ... {'type':'employee', 'name':'employee X', 'department_id':'department_1_id'}, {'type':'employee', 'name':'employee Y', 'department_id':'department_1_id'}, {'type':'employee', 'name':'employee Z', 'department_id':'department_2_id'}
Output that I need:
[
{
'name':'company A',
'departments':
[
{
'name':'department 1',
"employees":
[
{
'name': 'employee X'
},
{
"name": "employee Y"
}
]
},
{
"name":"department 2",
"employees":
[
{
"name": "employee Z"
}
]
}
]
},...
]