INSERT INTO default VALUES("1", {"name": "1","code": "1","countries": [{"_type": "Country","id": "212"},{"_type": "Country","id": "92"}]});
INSERT INTO default VALUES("2", {"name": "2","code": "2","countries": [{"_type": "Country","id": "100"}]});
INSERT INTO default VALUES("100", {"code": 100,"name":"Singapore"});
INSERT INTO default VALUES("212", {"code": 212,"name":"france"});
INSERT INTO default VALUES("92", {"code": 92,"name":"United States"});
The N1QL
SELECT a.code,a.name,
ARRAY_AGG({
"code":o.id,
"name":c.name
}) AS countries
FROM default a UNNEST a.countries o
JOIN default c ON KEYS (o.id)
WHERE a.countries IS NOT MISSING
GROUP BY a.code,a.name