Answers for "mongodb group by one field and then have all documents in that group as an array"

5

mongodb group by having

#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
])
Posted by: Guest on February-25-2021

Code answers related to "mongodb group by one field and then have all documents in that group as an array"

Python Answers by Framework

Browse Popular Code Answers by Language