How do I count multiple keys in the same MongoDB aggregation $group query?
问题 I have a query: db.test.aggregate( {$group : { _id : '$key', frequency: { $sum : 1 } } } ) This will get the frequency of every enumeration of key in the test set. Basically, I have gotten the distribution of key. Now imagine I want to get the distributions of key1, key2, and key3 (so three different distributions). Obviously, I could run this query 3 times with each separate key, but it seems like we would be able to optimize the query by allowing it to count all 3 keys at the same time. I