{
"sku" : "sku",
"price" : 0,
"name" : "name",
"attributes" : [
{
"name" : "fit",
"value" : "Regular",
"slug" : "regular",
"fit" : "regular"
},
{
"name" : "color_family",
"value" : "Red",
"slug" : "red",
"color_family" : "red"
},
{
"name" : "occassion",
"value" : "Casual",
"slug" : "casual",
"occassion" : "casual"
}
]
},
以上就是我蒙戈館藏結構,同時將$放鬆我的屬性鍵和屬性蛞蝓,申請組之後,然後通過收集得到兩次組.. 我的查詢是
db.products_mumbai.aggregate(
{$unwind : "$attributes"},
{$group : { _id : "$attributes.color_family", quantity : { $sum:1 } } })
的響應是
{ "_id" : "red", "quantity" : 21 }
{ "_id" : null, "quantity" : 126 }
錯誤在哪裏? –
我不希望null組中的空值由....然後我必須做..? –