In the controller/jobs.js -> showStats
When I try this code from the course it is not working for the new Mongoose version "mongoose": "^8.5.2":
const showStats = async (req, res) => {
let stats = await Job.aggregate([
{ $match: { createdBy: new mongoose.Types.ObjectId(req.user.userId) } },
{ $group: { _id: '$status', count: { $sum: 1 } } },
])
console.log(stats)
res.status(StatusCodes.OK).json({ defaultStats: {}, monthlyApplications: [] })
}
This is the issue from my console:

When you try the suggestion using the new it will work but there will be some deprecation warnings:

To solve the issue what I did is to use the string interpolation to make sure that I am passing a string.

Of course, if you're not using the new version of Node and Mongoose, this might not work for you.