Please help me resolve this error code Backend Development Mar 2023 Mar 2023 westkeystonecity 1 Mar 2023 My plea for help- Please, help! Error message- Mon

Error message-
throw new MongooseError('Model.findById() no longer accepts a callback

Code-

const UserModel = require("../models/user.model");
const ObjectID = require("mongoose").Types.ObjectId;

module.exports.getAllUsers = async (req, res) => {
  const users = await UserModel.find().select("-password");
  res.status(200).json(users);
};

module.exports.userInfo = async (req, res) => {
  console.log(req.params);

  if (!ObjectID.isValid(req.params.id))
    return res.status(400).send("ID unknown : " + req.params.id);

  UserModel.findById(req.params.id, (err, docs) => {
    if (!err) res.send(docs);
    else console.log("ID unknown : " + err);
  }).select("-password");
};

I see you posted some code, but can you add more details? what is happening? what should be happening instead?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.