Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Mongoose statics not found

Created a statics in a userModel.js such as userSchema.statics.login, and trying to refer to it in other file, but WebStorm is saying that is Unresolved function or method login(), pls help).

userSchema.statics.login = async function (email, password)  {
const user = await this.findOne({ email });
if(user){
    const auth = await bcrypt.compare(password, user.password);
    if(auth){
        return user;
    }
    throw Error('Incorrect password');
}
throw Error('Email doesn`t exist');
}
const User = mongoose.model('user', userSchema);
module.exports = User;

File in which i trying to refer:

const User = require("../models/userModel");
module.exports.login_post = async function (req, res) {
  const { email, password } = req.body;

  try {
      const UserLogin = await User.login(email,password);
    res.status(200).json({user: UserLogin._id});
  } catch (err) {
    res.status(400).json({})
  }

}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Fixed that by created a variable at the top of the file in which i want to call that function. Like that:

let User;
User = require("../models/userModel");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!