mongodb aggregate group

#It's the equivalent of the following SQL instruction:
# SELECT COUNT(*) FROM Table
# GROUP BY your_field
# HAVING COUNT(*) > N
query = db.collection.aggregate([

    { 
      "$group": { "_id": "$your_field", #GROUP BY your_field
    			"count": {"$sum":1} }   #COUNT(*)
    },
    
    { "$match": { "count": { "$gt": N } } } #HAVING COUNT(*) > N
])

Here is what the above code is Doing:
1. The first $group instruction groups the documents by the value of your_field and counts the number of documents in each group.
2. The second $match instruction filters the groups that have a count greater than N.