Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • model.FindById using MVC express js MongoDB pug is not working

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 369
    Answer it

    model.FindById using MVC express js MongoDB pug is not working(no error is also showing/id wise data is not being retrieved), please guide me.

    exports.getViewownerdata = (req,res,next)=>
    {
        const OwnerId= req.body._id;
        const mownername = req.body.ownername;
        const ownertype = req.body.ownertype;
        const owneraddress = req.body.owneraddress;
        const propertymanage = req.body.propertymanage;
                OwnerModel.findById(OwnerId)
                .then(owner=>{
                           owner.ownername = mownername;
                           owner.ownertype = ownertype;
                           owner.owneraddress = owneraddress;
                           owner.propertymanage = propertymanage;
                           return owner.save()
                        })
                        .then(result=>{
                                  res.render('/user/home_single');
                                      })
                        .catch(err=> {
                         errormessage =err;
                       res.redirect('/home');});
     }

     

 1 Answer(s)

  • Please add these lines to verify the response from the MongoDb query, as i can't see proper error handling @jaganrout

    OwnerModel.findById(OwnerId)
    .catch(error => console.log(error))

    .then(owner=>{console.log(owner)})

     
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: