【发布时间】:2019-12-20 16:30:35
【问题描述】:
使用 mongo 的 keystone js 出错:Vehicle.model.updateItem 不是函数 TypeError: Vehicle.model.updateItem 不是函数。
目标是使用对象更新模型,就像我使用 ff.代码如下。
CreateItems - Vehicle 是模型。而 postJson 是 json 数组对象。
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 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!!")
})
知道如何使用对象更新数据。 ?
【问题讨论】:
标签: javascript node.js mongodb mongoose keystonejs