30 lines
761 B
Python
30 lines
761 B
Python
def mangrove_by_country_latest():
|
|
pipeline = [
|
|
{
|
|
"$match": {"year": "2020"},
|
|
},
|
|
]
|
|
return pipeline
|
|
|
|
|
|
def mangrove_by_country_agg(query):
|
|
pipeline = [
|
|
{"$match": {"country_with_parent": query["country_with_parent"]}},
|
|
{
|
|
"$group": {
|
|
"_id": {"country_with_parent": "$country_with_parent", "year": "$year"},
|
|
"total_pixels": {"$sum": "$total_n_pixels"},
|
|
}
|
|
},
|
|
{
|
|
"$project": {
|
|
"_id": 0,
|
|
"country_with_parent": "$_id.country_with_parent",
|
|
"year": "$_id.year",
|
|
"total_pixels": 1,
|
|
}
|
|
},
|
|
{"$sort": {"year": 1}},
|
|
]
|
|
return pipeline
|