Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aradradev opened this issue Jul 31, 2024 · 2 comments

Comments

@aradradev
Copy link

aradradev commented Jul 31, 2024

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.

@aradradev aradradev changed the title 06.5 JOBSTER-API - ISSUE DEPRECATION 06.5 JOBSTER-API: showStats - ISSUE Mongoose version "mongoose": "^8.5.2" Jul 31, 2024
@aradradev aradradev changed the title 06.5 JOBSTER-API: showStats - ISSUE Mongoose version "mongoose": "^8.5.2" 06.5 JOBSTER-API: showStats - ISSUE Node: 20.x - Mongoose version "mongoose": "^8.5.2" Jul 31, 2024
@liamli99
Copy link

For the latest mongoose, please use mongoose.Types.ObjectId.createFromHexString(req.user.userId)!

@aradradev
Copy link
Author

For the latest mongoose, please use mongoose.Types.ObjectId.createFromHexString(req.user.userId)!

Yeah, this is another alternative, this might also work. However, using string interpolation worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants