I’m trying to query a specific repeating json object tree within a variable parent structure (with a static parent over THAT parent). I am stuck. I have tried using node.field, UNNEST, and use ARRAY… I’m not super good with N1QL so I’m probably doing something wrong. Any help is appreciated
Query Sample:
select *
from bucket as sc
where meta(sc).id = ‘somekey’
Can you fix desired output
{ “name”: “Breakfast available (surcharge)”,
“name”:“Laundry facilities”
}
Is not valid JSON. name is repeated and overwrite.
SELECT sc.*, ARRAY v.val.name FOR v IN OBJECT_PAIRS(sc.amenities) END AS amenities
from `bucket` as sc
where meta(sc).id = "somekey";
SELECT sc.property_id, sc.`321`.id AS id1, sc.`321`.name
from `bucket` as sc
where meta(sc).id = "somekey";
If you are doing search of document key USE KEYS will be better.
SELECT sc.*, ARRAY v.val.name FOR v IN OBJECT_PAIRS(sc.amenities) END AS amenities
from `bucket` as sc USE KEYS "somekey";
Basically your object has dynamic filed names. If you don’t know how construct path you can use OBJECT_PAIRS() which gives ARRAY of OBJECTS name, val pairs. Then you can use ARRAY collection to apply required dynamic field.