-
-
Save gharriso/52e47499ed32e837b3da138f86fe70bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.getCollection("lineitems").aggregate([ | |
{ $group:{ _id:{ "prodId":"$prodId" }, | |
"itemCount-sum":{$sum:"$itemCount"} } | |
}, | |
{ $sort:{ "itemCount-sum":-1 }}, | |
{ $limit: 10 }, | |
{ $lookup: | |
{ from: "products", | |
localField: "_id.prodId", | |
foreignField: "_id", | |
as: "product" | |
} | |
}, | |
{ $project: { | |
"ProductName": "$product.productName" , | |
"itemCount-sum": 1 , | |
"_id": 1 | |
} | |
}, | |
],{allowDiskUse: true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment