cannot get PUT to work on Nodejs / express
Kept at it and finally figured it out! Here is my PUT function.
app.put('/people/:id', function (req, res) {
var person = new PeopleModel({
first_name: req.body.first_name,
last_name: req.body.last_name,
// etc etc
});
var upsertData = person.toObject();
delete upsertData._id;
return PeopleModel.update({ _id: req.params.id }, upsertData, {upsert: true}, function(err) {
if (!err) {
return res.send("updated");
} else {
console.log(err);
return res.send(404, { error: "Person was not updated." });
}
});
});
I'm going to try and figure out how to auto detect what fields need to be updated, as just for testing i stored one var.