Last active
March 2, 2021 02:47
-
-
Save dgadiraju/64c8e0ea7dcb267ed874ad6a4dd5f8bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Count by order_status | |
db.orders. | |
aggregate([{"$group" : | |
{ "_id" : "$order_status", "status_count" : {"$sum" :1 }} | |
}, | |
{"$project" : | |
{ "order_status" : "$_id" , "status_count" : 1, "_id" : 0 } | |
}]) |
This file contains hidden or 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
// Get revenue for each order | |
db.order_items.find({"order_item_order_id" : 2}) | |
db.order_items. | |
aggregate([{"$group" : | |
{ "_id" : "$order_item_order_id", "order_revenue" :{ "$sum" : "$order_item_subtotal" }} | |
}, | |
{"$project" : | |
{ "order_item_order_id" : "$_id", "order_revenue" : 1, "_id" : 0 } | |
}]) |
This file contains hidden or 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
// Get revenue for order_id 2 | |
db.order_items. | |
aggregate([{ "$match" : {"order_item_order_id" : 2}}, | |
{"$group" : | |
{ "_id" : "$order_item_order_id", "order_revenue" : {"$sum" : "$order_item_subtotal"}} | |
}, | |
{"$project" : { "order_item_order_id": "$_id", "order_revenue" : 1, "_id" : 0 } | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment