DocumentDB Sub Query

后端 未结 1 1496
闹比i
闹比i 2021-01-21 16:16

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

相关标签:
1条回答
  • 2021-01-21 16:21

    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;
     }
    
    0 讨论(0)
提交回复
热议问题