I have the following objects and am trying to fund the total amount of funding for a specific industry in 2015.
{
"_id" : ObjectId("563549877befdba00db4abb2"),
"acquired_year" : 2015,
"industry" : "Games",
"company_info" : {
"company_name" : "Pinion.gg",
"price" : ""
}
}
I wrote this code to group by industry to find the total amount of acquisitions $$ spent for the specific industry, which worked.
db.acquisitions.aggregate([
{ $match: {"acquired_year":{$gte:2015} } },
{ $project : {"industry":"$company_market", acquired_year:1, "company_info": {"company_name":"$company_name", "price":"$acquistion_price"}}},
{ $group: {"_id":"$industry", "industry_funding":{$sum:"$company_info.price"}}}
])
Output is...
{
"_id" : "Semiconductors",
"industry_funding" : 18861500000
},
{
"_id" : "Coworking",
"industry_funding" : 0
},
{
"_id" : "Stock Exchanges",
"industry_funding" : 365000000
},
I'm trying to figure out how I could also list the top 5 companies with the highest acquisition prices for each industry. Anyone have any suggestions?