Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

mongodb aggregate group

#equivalent of the following SQL instruction:
# SELECT COUNT(*) FROM Table
# GROUP BY your_field
query = db.collection.aggregate([
    { 
        "$group": {
            "_id": "$your_field", #GROUP BY your_field
            "total": {"$sum":1}   #COUNT(*)
        }
    }
])
 
PREVIOUS NEXT
Tagged: #mongodb #aggregate #group
ADD COMMENT
Topic
Name
1+1 =