【发布时间】:2018-11-19 23:45:21
【问题描述】:
我的路线使用以下函数来总结注册的总收入。它在 shell 和 Studio3T 中运行良好,但 mongoose API 不返回任何内容。
我正在运行 mongoose 5.0.17 并使用 Azure Cosmos DB。
exports.getDhashboard = function (req, res) {
Registration.aggregate({
$group: {
_id: "$challenge.name",
totalAmount: { $sum: "$amount" },
count: { $sum: 1 }
}
}, function (err, registrations) {
if (err)
res.send(err);
res.json(registrations);
});
};
这是来自注册集合的一些示例 JSON。
{
"modified": "2018-06-09T15:43:02.288Z",
"_id": "5b1bf5863ace0d3f54be45b4",
"paymentState": "approved",
"paymentTimeStamp": "2018-06-09T15:43:02.000Z",
"paymentId": "PAY-1J368604337116737LMN7K3I",
"payPalBuyerEmail": "kameron.berget-buyer@theitfc.com",
"payPalBuyerId": "TTJC5ZWWEF9E6",
"address1": "1 Main St",
"city": "San Jose",
"state": "CA",
"zip": "95131",
"paymentMethod": "paypal",
"paymentStatus": "VERIFIED",
"amount": 20,
"user": "",
"__v": 0
},
{
"modified": "2018-06-10T14:58:49.422Z",
"_id": "5b1d3ca9d586d4697021c128",
"paymentState": "approved",
"paymentTimeStamp": "2018-06-10T14:58:46.000Z",
"paymentId": "PAY-0D492814K5815962PLMOTZCQ",
"payPalBuyerEmail": "",
"payPalBuyerId": "TTJC5ZWWEF9E6",
"address1": "1 Main St",
"city": "San Jose",
"state": "CA",
"zip": "95131",
"paymentMethod": "paypal",
"paymentStatus": "VERIFIED",
"amount": 20,
"user": "",
"__v": 0
}
【问题讨论】:
-
我使用的是 Mongoose 5.0.17,我的数据库托管在 Azure Cosmos DB 中。
-
我在这里没有看到任何与该问题相关的数据。由于没有相关数据,这个问题毫无意义,我提名关闭。
标签: mongodb mongoose aggregate