xxxxxxxxxx
#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(*)
}
}
])
xxxxxxxxxx
#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
])
xxxxxxxxxx
# Encontrar el valor máximo para el ancho del pétalo - Opción 3
agg_result = Collection.aggregate([
{"$group":
{ "_id":"_id",
"std": { "$stdDevPop": "$petalWidth" }
}
}
])
xxxxxxxxxx
{
"_id":"26/04/2015 09:50",
"reservations":130,
"Event_types":[
{
"type":"Party",
"events":[
{
"eventName":"After Party",
"total_count":130,
"by":[
{
"siteName":"club8",
"countArray":[
{
"bucket":"default",
"value":40
}
]
},
{
"siteName":"PostParty",
"countArray":[
{
"bucket":"1",
"value":70
},
{
"bucket":"2",
"value":20
}
]
}
]
}
]
}
]
}