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 ?
Both purchaseOrder
and product
are read from the database using mongoose.findOne()
.
Have you tried parsing the parameter as an object? As in {position: product._id}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.