[英]Mongoose programatically update single array property item
I'm trying to update a single array property item using mongoose: 我正在尝试使用猫鼬更新单个数组属性项:
const updatePurchaseItem = async (purchaseOrder, itemIndex, product) => {
let position = "items." + itemIndex + ".product_id";
let query = {
_id: purchaseOrder._id,
deletedAt: null
};
await PurchaseOrderModel.update(query, position: product._id);
}
I'm getting the following error: 我收到以下错误:
Cast to ObjectId failed for value "items.1.product_id" at path "_id" for model "PurchaseOrder"
What is the code proper syntax to make this work? 使此工作正常的代码正确语法是什么?
What does path "_id"
means ? path "_id"
是什么意思?
Both purchaseOrder
and product
are read from the database using mongoose.findOne()
. 无论
purchaseOrder
和product
从数据库中读取使用mongoose.findOne()
Have you tried parsing the parameter as an object? 您是否尝试过将参数解析为对象? As in
{position: product._id}
如
{position: product._id}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.