Skip to content

06.5 JOBSTER-API: showStats - ISSUE Node: 20.x - Mongoose version "mongoose": "^8.5.2" #81

@aradradev

Description

@aradradev

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:

issueJobs

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

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

fixed

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions