Ich versuche, mit diesem Code zu finden und zu aktualisieren:Mongoose findByIdAndUpdate() findet/Rendite-Objekt, aber nicht aktualisiert
exports.updatePlot = async (req, res) => {
let modifications = {};
modifications.name = req.body.name;
modifications.grower = req.body.props.grower;
modifications.variety = req.body.props.variety;
modifications.planted = req.body.props.planted;
const id = req.body.props.id;
try {
const updatedPlot = await Plot.findByIdAndUpdate(
id,
{ $set: { modifications } },
{ new: true }
);
res.json({
updatedPlot
});
} catch (e) {
return res.status(422).send({
error: { message: 'e', resend: true }
});
}
};
Ich kann sehen, dass meine Anfrage Körperdaten enthält, kann ich auch sehen, dass Mungo das Objekt ist zu finden, aber die Aktualisierung nicht, denn das ist, was sie als die aktualisierte Plot protokolliert:
{"_id":"id string here","name":"old name",...all other properties...}
ich denke, meine Anfrage ungültig ist? Wer sieht meinen Fehler?
Das Schema sieht wie folgt aus:
const plotSchema = new Schema(
{
name: String,
...other properties...
},
{ bufferCommands: false }
);
const ModelClass = mongoose.model('plot', plotSchema);