skip to Main Content

Mongodb – Unable to get document using document.findOne()

I tried to get a document using document.findOne() but it's value is showing undefined . Here is my code `app.post("/studentlogin",(req,res)=> { let password; console.log("login page"); bcrypt.hash(req.body.password,saltRounds,(err,hash)=> { const user= Student.findOne({srno:req.body.srno}); console.log(user.srno); if(req.body.srno==user.srno && hash==user.password) { session=req.username; session.userid=req.body.srno; res.redirect("/"); } else{…

VIEW QUESTION

MongoDB/Mongoose : CastError in updateMany $inc

My MongoDB schema (simplified): user: ObjectID calories: Number meals:[{ calories: Number name:String }] And I have a updateMany query: await Meals.updateMany( { user: user, 'meals.name': extraMealName }, { $inc: { calories: 'meals.$.calories' } }, {multi : true}, function(error, result) {…

VIEW QUESTION
Back To Top
Search