I've been attempting to update an item in my mongodb database, but I'm encountering issues as the error keyword is being set to undefined. It's possible that I am making a mistake somewhere. Here's the code for the update function:
router.post("/file/:id/edit", (req, res) => {
var id = req.params.id;
File.findOneAndUpdate( {"_id": id} , req.body, (err) => {
if (err) return res.json({ success: false, error: err });
return res.json({ success: true });
});
});
This is how the update is triggered:
export function updateFile(file) {
var objIdToUpdate = file["id"];
var myUpdate = axios.post("http://localhost:3001/api/file/:" + objIdToUpdate + "/edit", {
title: file.title,
author: file.author,
dateCreated: file.dateC,
dateModified: file.dateModified,
size: file.size,
type: file.type,
tags: file.tags
});
return myUpdate;
}
Here's my schema:
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const FileSchema = new Schema(
{
title: String,
author: String,
dateCreated: String,
dateModified: String,
size: String,
type: String,
tags: []
},
{ timestamps: true }
);
module.exports = mongoose.model("File", FileSchema, "files");
Despite trying to print the "err" keyword, it remains undefined. What could be causing this issue with updating values in my database?