我在MongoDB中以下客戶訂單數據
"_id" : 7,
"customer name" : "John Smith",
"OrderItem" : [
{
"product_category" : "Mobile",
"price" : 900
},
{
"product_category" : "Computer",
"price" : 4200.48
},
{
"product_category" : "TV",
"price" : 670.20
},
{
"product_category" : "TV",
"price" : 960.52
}
]
我需要平均每個產品類別是這樣的:
"_id" : 7,
"customer name" : "John Smith",
"OrderItem" : [
{
"product_category" : "Mobile",
"price" : 900
},
{
"product_category" : "Computer",
"price" : 4200.48
},
{
"product_category" : "TV",
"price" : 815.36
}
]
我試着使用$展開,但不知道如何分組。任何幫助?
你究竟如何嘗試? – 2015-04-01 09:41:41
'product_category'或'product_name'? – Yogesh 2015-04-01 09:44:47