From b74227c9a1ad2cc78b960bb81365bdf905503fd5 Mon Sep 17 00:00:00 2001 From: tayyabakhtar62 Date: Sat, 19 Dec 2020 22:52:37 +0500 Subject: [PATCH] added new functionality --- app.js | 3 ++- routes/index.js | 10 ++++------ views/index.pug | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index bd6dc5c..bcde33b 100644 --- a/app.js +++ b/app.js @@ -12,7 +12,8 @@ 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..6e555a2 100644 --- a/routes/index.js +++ b/routes/index.js @@ -48,13 +48,11 @@ 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("Updating data failed!"); } + res.redirect('/users'); }); } } diff --git a/views/index.pug b/views/index.pug index 64c1acd..dcb6792 100644 --- a/views/index.pug +++ b/views/index.pug @@ -11,7 +11,7 @@ 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