Hello, everyone.
I have the following structures.
Menu (root object):
{ "id": 1, "dishes": [{ "dishId": 1, "amount": 5 }] }
Dish: (subobject)
{ "id": 1, "nutrients": [{ "nutId": 1, "amount": 4 }], "products": [{ "prodId": 1, "amount": 8 }] }
Nutrient: (subsubobject)
{ "id": 1, ... }
Product: (subsubobject)
{ "id": 1, ... }
I need to get a recursively nested structure like the following:
[{ "id": 1, "dishes": [{ "dishId": 1, "amount": 5, "dish": { "nutrients": [{ "nutId": 1, "amount": 4, "nutrient": {...} }], "products": [{ "prodId": 1, "amount": 8, "product": {...} }] } }] }, ... ]
I am a newbie, so I’ve been able to manage only one level of nested objects. Something like that:
SELECT MENU.*, dishes FROM bucket AS MENU UNNEST MENU.dishes AS DA JOIN bucket AS DISH ON DISH.id = DA.dishId GROUP BY MENU LETTING dishes = ARRAY_AGG(OBJECT_PUT(DA, "dish", DISH))
I don’t have any idea how to get a deeper level of nested objects. I am currently using Community Edition 6.0.0 build 1693.
PS. Sorry for my English, it’s not my first language.