Hi
The post method does not work for me.
The problem is with the _id : when I send :
{
“_id” : “3”,
“name” : “Sci-fi”
}
from postman I get error message as response:
“_id” is not allowed
But even when I don’t use the id so I send from postman:
{
“name” : “Sci-fi”
}
I get error on console : document must have an _id before saving.
I’m using Atlas cloud from MongoDB and not local, I think this might be the cause ? So if I want to insert an Id myself I simply can’t ? Please help.
Here is my method:
router.post(’/’,async function createGenre(req,res) {
const { error } = validateGenre(req.body);
if (error) return res.status(400).send(error.details[0].message);
const genre = new Genre ({
//_id: req.body.id,
name: req.body.name
});
try {
const result = await genre.save();
res.send(result);
}
catch (ex) {
console.log(ex.message);
}
});
Thanks in advance.