[英]Mongoose delete array item in every subdocument
我有一個用戶(單擊) Model,其中有一個存儲產品的購物車(只是 id)。 如果我想從商店中刪除產品,該產品也應該從每個用戶購物車中刪除。
因此我嘗試了這段代碼:
User.update({ $pull: {'cart.items': {productId: product._id }}});
即使我想使用 findByIdAndUpdate 從特定用戶中刪除產品,它也不起作用:
User.findByIdAndUpdate(user._id, { $pull: {'cart.items': {productId: product._id }}});
試試看嘛:
User.update({},{ $pull: {'cart.items': {productId: product._id }}});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.