Я пытаюсь обновить название категории. Но я застрял в TypeError: category.save не является функцией. Вот код:
exports.updateCategory = (req, res) => {
console.log(req.body)
const category = req.body;
category.name= req.body.name;
category.save((err, updatedCategory) => {
if (err) {
return res.status(400).json({
error: "Failed to update category"
});
}
res.json(updatedCategory);
});
};
Здесь ошибка:
{ name: 'rainy' }
TypeError: category.save is not a function
at exports.updateCategory (C:\Users\Admin\Desktop\MERN\projbackend1\controllers\category.js:54:14)
at Layer.handle [as handle_request] (C:\Users\Admin\Desktop\MERN\projbackend1\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Admin\Desktop\MERN\projbackend1\node_modules\express\lib\router\route.js:137:13)
at exports.isAdmin (C:\Users\Admin\Desktop\MERN\projbackend1\controllers\auth.js:94:3)
at Layer.handle [as handle_request] (C:\Users\Admin\Desktop\MERN\projbackend1\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Admin\Desktop\MERN\projbackend1\node_modules\express\lib\router\route.js:137:13)
at exports.isAuthenticated (C:\Users\Admin\Desktop\MERN\projbackend1\controllers\auth.js:85:3)
at Layer.handle [as handle_request] (C:\Users\Admin\Desktop\MERN\projbackend1\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Admin\Desktop\MERN\projbackend1\node_modules\express\lib\router\route.js:137:13)
at C:\Users\Admin\Desktop\MERN\projbackend1\node_modules\express-jwt\lib\index.js:128:7
at C:\Users\Admin\Desktop\MERN\projbackend1\node_modules\async\lib\async.js:52:16
at Immediate.<anonymous> (C:\Users\Admin\Desktop\MERN\projbackend1\node_modules\async\lib\async.js:1206:34)
at processImmediate (internal/timers.js:456:21)
Любая помощь будет полезна, спасибо