📜  mongodb group by have - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:05.044000             🧑  作者: Mango

代码示例1
#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
])