I am trying to project from a large document containing a double nested array, into a flattened representation of the array, and I am stuck on how to proceed.
I have doc
DocumentDB support for sub-queries is planned, but not currently supported. Meanwhile, UDFs or pulling the data client side as N records, then re-formatting is the best way to do this today. For others interested, here's a UDF for returning the results in the query,
function transform(doc) {
var result = {};
for (var prop in doc) {
if (prop != "componentGroups") {
result[prop] = doc[prop];
} else {
result["components"] = [];
for(var cgidx in doc["componentGroups"]) {
var componentGroup = doc["componentGroups"][cgidx];
for (var cidx in componentGroup) {
var component = componentGroup[cidx];
result["components"].push({componentType: component.componentType, enabled: component.enabled });
}
}
}
}
return result;
}