これらは私の文書である:マングースの集計:_idないフィールドを返す
{shopId: "aaa", customerId: "bbb", customerName: "xxx", value: 12}
{shopId: "aaa", customerId: "ccc", customerName: "yyy", value: 12}
{shopId: "aaa", customerId: "bbb", customerName: "xxx", value: 12}
{shopId: "ddd", customerId: "bbb", customerName: "xxx", value: 12}
私は与えられた顧客が選択したお店で過ごしたどのくらいのお金を知りたいです。
私はそれを行う方法を知っている:
Docs.aggregate(
[{ $match: { shopId: selectedShop } },
{
$group: {
_id: "$customerId",
totalVisits: { $sum: 1 },
totalValue: { $sum: "$value" }
}
}
], function (err, result) {
if (err) {
//
} else {
//
}
}
);
問題は、私が得る結果は_id: "$customerId"
フィールドが含まれていると私はcustomerName
を取得し、customerId
を非表示にすることです。
可能ですか?
お客様の名前は一意ではないため、私はそれをグループ化することはできません。 –
ああ、私はちょうどあなたの質問のダミーのデータのためにそれを仮定:) – DAXaholic