Question
help with error ***MongoServerError: Performing an update on the path '_id' would modify the immutable field '_id'***** This is for an edit button, the link
help with error
***MongoServerError: Performing an update on the path '_id' would modify the immutable field '_id'*****
This is for an edit button, the link works but for some reason when i change the data on the edit page and hit submit the whole website crashes
here is the line of code, let me know if you see any errors i may have missed
">Edit
export function displayEditPage(req, res, next) {
let id = req.params.id;
booksModel.findById(id, function(error, book){
if (error) {
console.error(error);
res.end(error);
}
res.render('index', {title: ' Edit Book', page: 'books/edit', book})
})
}
// POST process the Book Details page and create a new Book - CREATE
export function processEditPage(req, res, next) {
let id = req.params.id
let editBook = booksModel({
_id: req.body.id,
name: req.body.name,
author: req.body.author,
published: req.body.published,
description: req.body.description,
price: req.body.price,
});
booksModel.updateOne({_id: id},editBook,function(error, book){
if (error) {
console.error(error);
res.end(error);
}else{
res.redirect('/books/list');
};
//res.redirect('/books/list');
});
// GET the Book Details page in order to edit an existing Book
router.get('/books/edit/:id', displayEditPage);
// POST - process the information passed from the details form and update the document
router.post('/books/edit/:id', processEditPage);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started