【发布时间】:2020-05-15 20:48:54
【问题描述】:
我想使用 mongoose 更新嵌套对象中的数据。我的模型是这样的:
{
_id: 123,
shoppingCart: [{
_id: 321,
totalPrice: 110,
itemCount: 1,
items: [{
title: "product123",
quantity: 2
}]
}]
}
我想更新购物车的商品数量。我阅读了文件,但我不明白如何更新数量?
【问题讨论】:
-
暂时不考虑猫鼬,可以像
obj.shoppingCart[0].items[0].quantity = 3;一样更改数量。不过,这看起来像是一个填充的数据库结果,所以我认为这不是要走的路。
标签: javascript node.js mongodb mongoose