After I manually changed a field name in mongoDb, my crud operations no longer work. I have read that in this case the old and new field name in mongoose. Schema must be specified, and have done so, but the database still does not take the values. Do I also have to specify something in my routes in node?
That is the route in node:
router.post("/", upload.single("img") ,verifyTokenAndAuthorization, async (req,res)=>{
try{
const result = await cloudinary.uploader.upload(req.file.path, {
upload_preset: "Mern_redux-practice",
resource_type: "auto",
}) //cloudinary gets data, so the data must be here
const newDayLinks = new Daylinks({
cloudinary_id: result.public_id,
title: req.body.title,
content:req.body.content,
img: result.secure_url,
ident: req.body.ident, //this is the new fieldname and it is undefined
})
const savedDayLinks = await newDayLinks.save();
res.status(200).json(savedDayLinks);
} catch(error){
res.status(403)
console.log(ident, title, content,img);
throw new Error("Action failed"); //this error is thrown
}
});
That is the current mongoose Schema:
const DaylinksSchema = new mongoose.Schema({
cloudinary_id: {type:String, required:true},
img:{type:String, required:true},
title:{type:String, required:true},
content:{type:String, required:true},
id:{type:String}, //that was the fieldname before
ident:{type:String, required:true}, // that is the new fieldname I manually changed in the collection
},
{timestamps:true},
);
module.exports = mongoose.model("Daylinks", DaylinksSchema);