From 7dbf0d8283c570e4deffbce03523816b8ff52a92 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 20 Dec 2020 01:24:11 +0500 Subject: [PATCH] Updated --- app.js | 6 +++++- routes/index.js | 9 ++++----- views/index.pug | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index bd6dc5c..3871046 100644 --- a/app.js +++ b/app.js @@ -12,7 +12,11 @@ const app = express(); var mongoose = require('mongoose'); mongoose.connect(process.env.DATABASE, { useNewUrlParser: true, - useUnifiedTopology: true + useUnifiedTopology: true, + useFindAndModify: false + + + }); mongoose.connection diff --git a/routes/index.js b/routes/index.js index 15971f0..cfb1a25 100644 --- a/routes/index.js +++ b/routes/index.js @@ -48,13 +48,12 @@ router.post('/',[ function updateUser(req, res){ const errors = validationResult(req); if(errors.isEmpty()){ - User.findOneAndUpdate({_id: req.body._id}, req.body, {new: true}, (err, user) => { - if(!err) { - req.redirect('/users'); - } else{ - console.log(err); + User.findOneAndUpdate({_id: req.body._id}, {$set:req.body}, {new: true}, (err, doc) => { + if (err) { + console.log("Something wrong when updating data!"); } + res.redirect('/users'); }); } } diff --git a/views/index.pug b/views/index.pug index 64c1acd..42ae4e4 100644 --- a/views/index.pug +++ b/views/index.pug @@ -11,7 +11,8 @@ block content ul for error in errors li= error.msg - form(class="form-registration", action = ".", method = "POST" autocomplete="false") + form(class="form-registration", action = "/", method = "POST" autocomplete="false") + input(type="hidden", name="_id" value=data._id) - var h1Classes = ['h3', 'mb-3', 'font-weight-normal'] h1(class=h1Classes) Enter User Details to be Add