У меня есть Item
модели,мангуста: findByIdAndUpdate через Erro «сообщение»: «Cast нанизывать Сбой значения » неопределенное »
var mongoose = require('mongoose');
var ItemSchema = new mongoose.Schema({
title: {type: String, es_indexed:true},
price: Number,
description: {type: String, es_indexed:true},
picture: String,
vendor: {type: String, es_indexed:true},
vendorId: String,
vendorPicture: String,
category: String
});
module.exports = mongoose.model('Item', ItemSchema);
Что я пытаюсь сделать, это извлечь элемент с помощью Id и обновления :
app.put('/api/item/:id', ensureAuthenticated, function(req, res) {
Item.findByIdAndUpdate(req.params.id,
{title: req.body.title, description: req.body.description, price: req.body.price},
function(err, item) {
if(err) {
res.send(err);
return;
}
res.send('product updated');
});
})
, но я получил в ответ и ошибки, и я не могу понять, почему, вот Erorr:
{"message":"Cast to string failed for value \"undefined\" at path \"title\"","name":"CastError","type":"string","path":"title"}
'log' your' req.body', что вы видите? По какой-то причине он не может передать его в 'String' – danillouz
это тело' {title: 'новое название', описание: 'look dress', price: 150} ' –