I need help to build N1QL query for a document with contents.
I do have exact documentId but inside the document there is a json and i want to know how many keys have values >30
Document sample ,
Here , no of keys with with values greater than 30 are 3 (as ‘c’ , ‘d’ , ‘e’ have values greater than 30).
SELECT ARRAY_SUM(ARRAY 1 FOR v IN OBJECT_VALUES(d) WHEN v > 30 and is_num(v) END) AS cnt FROM default AS d USE KEYS "<yourkey>";
For this solution , i Will have to know the key , right? But i have to do it for all keys at root level and not for selected keys…
Can be any no of keys…
How to write query to fetch the same for ALL keys at root level?
Argument to OBJECT_VALUES() provide path of the object
SELECT d.* FROM default AS d ANY v IN OBJECT_VALUES(d) WHEN v > 30 and is_num(v) END ;