I am trying to UPDATE fields in mongo database. However, I get the hollowing error.
MongoError: Performing an update on the path '_id' would modify the immutable field '_id'
My Code to update.
app.put("/api/inventory/:sku", (req, res, next) => {
const inventory = new Inventory({
_id: req.body.id,
sku: req.body.sku,
total_qty: req.body.total_qty,
current_qty: req.body.current_qty
});
Inventory.updateOne({ sku: req.params.sku }, req.body).then(result => {
res.status(200).json({ message: "Update successful!" });
});
});