0
我使用它來獲得我想要的結果,基本上我需要來自每個供應商的總收入。MongoDB組在密鑰中檢索爲空
db.lineitems.group(
{
key : {"$partsupp.supplier.suppkey" : 1},
cond : { "shipdate" : {"$gte":19960101,"$lt":19960401}},
reduce : function (curr, result) {
result.totalgroup+=curr.extendedprice*1-curr.discount;
},
initial : {totalgroup : 0}
}
)
,結果是這樣的:
[
{
"$partsupp.supplier.suppkey" : null,
"totalgroup" : 208208820.8400005
}
]
這回所有供應商收入的總和。