How to do HAVING COUNT in MongoDB?
<p>My documents look like this:</p>

<pre><code>{
    "_id": ObjectId("5698fcb5585b2de0120eba31"),
    "id": "26125242313",
    "parent_id": "26125241841",
    "link_id": "10024080",
    "name": "26125242313",
    "author": "gigaquack",
    "body": "blogging = creative writing",
    "subreddit_id": "6",
    "subreddit": "reddit.com",
    "score": "27",
    "created_utc": "2007-10-22 18:39:31"
}
</code></pre>

<p>What I'm trying to do is create a query that finds users who posted to only 1 subreddit. I did this in SQL by using the query:</p>

<pre><code>Select distinct author, subreddit from reddit group by author having count(*) = 1;
</code></pre>

<p>I'm trying to do something similar in MongoDB but are having some troubles atm.
I managed to recreate select distinct by using aggregate group but I can't figure out how to solve the HAVING COUNT part.</p>

<p>This is what my query looks like:</p>

<pre><code>db.collection.aggregate( 
[{"$group": 
    { "_id": { author: "$author", subreddit: "$subreddit" } } },
    {$match:{count:1}} // This part is not working
])
</code></pre>

<p>Am I using $match wrong?</p>