Data.model.updateItem不是函数TypeError:Data.model.updateItem不是函数 [英] Data.model.updateItem is not a function TypeError: Data.model.updateItem is not a function
问题描述
使用mongo的梯形校正js错误:Vehicle.model.updateItem不是函数TypeError:Vehicle.model.updateItem不是函数.
Error in keystone js using mongo : Vehicle.model.updateItem is not a function TypeError: Vehicle.model.updateItem is not a function .
目标是使用对象更新模型,就像我使用ff创建商品的方式一样.下面的代码.
The goal is to update the model using an object just like how I did create Items using the ff. code below.
keystone.createItems({
Vehicle: postJson
}, function (err, stats) {
if (err) return res.json(err);
res.json({
data: stats.message
});
console.log("Succeeded!!")
});
现在,我正在尝试使用对象的json数组和唯一ID更新模型上的数据,其中itemToUpdate是与要更新的文档匹配的查询,而fieldToUpdate是包含所需字段的对象一个新的价值.但这会引发错误Vehicle.model.updateItem不是函数TypeError:Vehicle.model.updateItem不是函数
Now I am trying to update data on the model using an json array of object and with the unique id where itemToUpdate is the query to match the document I want to update and the fieldToUpdate is the object containing the field/fields you want a new value for. But it raises an error Vehicle.model.updateItem is not a function TypeError: Vehicle.model.updateItem is not a function
var itemToUpdate = {
vin_no: value.vin_no
}
var fieldToUpdate = {
Vehicle: value
}
Vehicle.model.updateItem(
itemToUpdate,
fieldToUpdate,
function (err, stats) {
if (err) return res.json(err);
res.json({
data: stats.message
});
console.log("Succeeded!!")
})
关于如何使用对象更新数据的任何想法. ?
Any idea how we can update data using objects. ?
推荐答案
您应该像这样使用它
// assuming value is object with all the fields.
var itemToUpdate = {
vin_no: value.vin_no
}
Vehile.model.findOne(itemToUpdate, function(error, vehicleObject) {
Vehicle.updateItem(
vehicleObject,
value,
function (err) {
// err can be Error object or an object with 'error' and/or 'detail' property
if (err) return res.json(err);
res.json({
status: "success"
});
console.log("Succeeded!!")
})
})
如果itemToUpdate
的字段数可变,则可以为此调用添加选项
if itemToUpdate
has variable number of fields, you can add option to this call as
var options = { field: 'vin_no, model_year, num_owners' }
并将其作为Vehicle.updateItem(Vehicle.model, itemToUpdate, options, callback)
这篇关于Data.model.updateItem不是函数TypeError:Data.model.updateItem不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!