I'm trying to update a mongoDB database document for my To-Do list, I'm using Node, Mongoose, Express and Express Router.
Mongoose Schema:
const mongoose = require('mongoose');
const toDoSchema = new mongoose.Schema({
value: {
type: String,
},
category: {
type: String,
},
_id: {
type: String
}
});
module.exports = mongoose.model('toDo', toDoSchema)
Patch code:
router.patch('/changeCategory', async (request, response) =>{
const updateItem = new toDoModel({
category: request.body.category
})
let id = request.body._id
let category = request.body.category
try{
await updateItem.findByIdAndUpdate({_id: id},{category: category})
response.json('Category changed')
}
catch (error){
console.log(error.message)
}
})
Insomnia request:
PATCH http://localhost:5000/changeCategory
{
"category":"inProgress",
"_id": "628de6210da8e45f52217083"
}
and what i get is "updateItem.findByIdAndUpdate is not a function"