I am trying to update an existing entry using Mongoose. The insert is OK, but not an update.
Here is my snippet:
app.post('/submit', function(req, res) { var my_visit = new models.visits({ date: req.body.visit_date, type: req.body.visit_type, agency: req.body.visit_agency, city: req.body.visit_city, url: req.body.visit_url, note: req.body.visit_note }); // INSERT if(req.body.id == 0) { my_visit.save(function(err) { if(err) { throw err; } console.log('added visit'); res.redirect('/'); }); } else { // UPDATE var upsertData = my_visit.toObject(); console.log(req.body.id); // OK models.visits.update({ _id: req.body.id }, upsertData, { multi: false }, function(err) { if(err) { throw err; } console.log('updated visit: '+ req.body.id); res.redirect('/'); }); } })
Answer Mod on _id is not allowed .
I just want to update a row like WHERE id = id in MySQL. I did not find the correct syntax.
source share