How to update a record by hard coding the MLAB ID in the server using app.post.
Any help would be great.
Thanks
Answered
Try updating your record instead of inserting a new one. To update your record your record must contain an immutable field.
Refer this question to see how to find and update with mongoose
Try this:
app.post('/form1', function (req, res, next) {
record.findOneAndUpdate({"_id": ObjectId("THE ID IN MLAB")}, req.body, {new: true}, function (err, doc) {
if (err) {
res.status(500).end()
} else {
res.status(200).end()
}
})
});
Documentation: https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate