CRETAE INDEX ix1 ON bucket(active) WHERE _type = "Listener";
SELECT t.*
FROM bucket AS t
WHERE t._type = "Listener" AND t.active = true;
If whole thing is one document and you want get only those nested objects that has active true
CREATE INDEX ix2 ON bucket(DISTINCT ARRAY v.active FOR v IN OBJECT_VALUES(self) END);
SELECT RAW OBJECT n:v FOR n:v IN t WHEN v.active = true END
FROM bucket AS t
WHERE ANY v IN OBJECT_VALUES(t) SATISFIES v.active = true END;
How do I get the result as single document. like:
{
“SCP_1”: {
“active”: true,
“jobId”: “345”,
“dataSourceCode”: “abc”,
“activationTime”: “0001-01-01T00:00:00”,
“_type”: “Listener”
},
“SCP_3”: {
“active”: true,
“jobId”: “888”,
“dataSourceCode”: “abc”,
“activationTime”: “0001-01-01T00:00:00”,
“_type”: “Listener”
}
}
Getting multiple objects from different document and forming one document can have loss of data because object field names must be unique. How Do u resolve them?
CREATE INDEX ix1 ON bucket(ALL ARRAY u.val.active FOR u IN OBJECT_PAIRS(self) END);
SELECT RAW OBJECT v.name:v.val
FOR v IN ( SELECT RAW u FROM bucket AS t UNNEST OBJECT_PAIRS(t) AS u WHERE u.val.active = true)
END;