Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Expense
- .aggregate(
- [
- {
- $match: {
- creator: new mongoose.Types.ObjectId(req.userId)
- }
- },
- {
- $group :
- {
- _id : "$category",
- totalSaleAmount: { $sum: "$amount" }
- }
- }
- ]
- )
- .then(result => {
- res.status(200).json({ message: 'Expense By Category for current User', expensesByCategory: result });
- })
- .catch(err => {
- if (!err.statusCode) {
- err.statusCode = 500;
- }
- next(err);
- })
Advertisement
Add Comment
Please, Sign In to add comment