【发布时间】:2022-01-19 17:03:26
【问题描述】:
这是我的 mongo-DB 数据库集合图像 [1]:https://i.stack.imgur.com/TIKh1.png
我想添加查询,其中我需要按月获取分组以及从嵌入在(usermodel)集合中的(项目)数组中的(数量)总和
这是我目前的做法,但在控制台中没有显示输出
router.get('/calculatedata', Authenticate, async (req, res) => {
try {
const getUser = await UserModel.findById({ _id: req.userID });
const getProject = await getUser.aggregate([
{$unwind: '$project' },
{$group: { _id: { month: "$month" },
total:{$sum:"$project.amount"}
}
}]);
console.log(getProject)
} catch (error) {
res.status(400).send({ message: "Something Went Wrong" })
}
})
【问题讨论】:
-
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。
标签: javascript node.js mongodb express mongoose