В client.save () ниже у меня есть следующая ошибка (которая перехватывается правильно):
DocumentNotFoundError: Документ не найден для запроса "{_id: '5bfbce595be7d1047c976e6b'}"
app.put('/api/client', function (req, res) {
Client.findOne(new mongoose.Types.ObjectId(req.body._id)).then(client => {
//This is OK, I can see client and its properties
client.name = req.body.name;
//This is OK, I can see the updated client and its properties
client.save().then(test => {
console.log("ERR=" + err);
console.log(test);
}).catch(err => console.log("ERR :" + err));
res.json(client);
});
});
Модель такова:
mongoose.model('Client', {
_id: {type: String, default: ''},
name: {type: String, default: ''},
creationDate: {type: Date, default: ''}
});
Как получается, что документ найден в FindOne () и больше нет в save ()?