0

We have several map-reduce jobs that run on a scheduler and aggregate some counts for us. We'd like to switch these over to real time aggregate calls. The problem is, the map-reduce in all it's infinite flexibility is tallying 4 different counts for the collection it runs against. Things like:

var result =
    {
        MessageId: this.MessageId,
        Date: this.Created,
        Queued : (this.Status == 0 ? 1 : 0),
        Sent : (this.Status == 1 ? 1 : 0),
        Failed : (this.Status == 2 ? 1 : 0),
        Total : 1,
        Unsubscribes: 0
    };

If I were in SQL I don't think I could pull this off with a single GROUP BY/SUM, because I need a different filter for each SUM. Is it possible in mongo, or do I need to run 4 separate $group statements with different $match clauses?

4

0 回答 0