N1QL select to find array index


#1

I have the following structure (taken from the tutorial)
"results": [ { "orderlines": [ { "productId": "coffee01", "qty": 1 }, { "productId": "sugar22", "qty": 1 } ] }, { "orderlines": [ { "productId": "coffee01", "qty": 2 }, { "productId": "tea111", "qty": 1 } ] }

I want to be able to find all orderlines that have any index that is equal to tea111. Is this a way to this generally or I need to compare each index separately?


#2

return orderlines when any one contain “tea11”

SELECT orderlines 
FROM default 
WHERE ANY v IN orderlines SATISFIES v.productId = "tea111" END;

return orderlines when any one contain “tea11” and remove other ones from output

SELECT ARRAY v FOR v IN orderlines  WHEN  v.productId = "tea111" END;
FROM default 
WHERE ANY v IN orderlines SATISFIES v.productId = "tea111" END;

https://blog.couchbase.com/working-json-arrays-n1ql/