MongoDB aggregate/grouping by key-value pairs
<p>My data looks something like this:</p>

<pre><code>    { 
            "_id" : "9aa072e4-b706-47e6-9607-1a39e904a05a", 
            "customerId" : "2164289-4", 
            "channelStatuses" : {
                    "FOO" : {
                    "status" : "done"
                    }, 
                    "BAR" : {
                    "status" : "error"
                    }
            }, 
            "channel" : "BAR", 
    }
</code></pre>

<p>My aggregate/group looks like this:</p>

<pre><code>    { 
            "_id" : {
                    "customerId" : "$customerId", 
                    "channel" : "$channel", 
                    "status" : "$channelStatuses[$channel].status"
            }, 
                    "count" : {
                    "$sum" : 1
            }
    }
</code></pre>

<p>So basically with the example data the group should give me a group grouped by:    </p>

<pre><code>   {"customerId": "2164289-4", "channel": "BAR", "status": "error"}
</code></pre>

<p>But I cannot use []-indexing in a aggregate/group. What should I do instead?</p>