【发布时间】:2020-07-27 06:12:06
【问题描述】:
我有这个模型:
const cart = new mongoose.Schema(
{
products: [{
productId: {
type: mongoose.Schema.Types.ObjectId,
ref: "Product",
},
quantity: {
type: Number,
required: true,
default: 1
},
title: String,
price: Number
}],
},
{ timestamps: true });
我如何使用它找到我的所有产品(来自 Model Product)。
cart = Cart.find(id);
// inside cart.products
[{productId: 'asvhbajAS13', quantity: 8 },{productId: 'asvhbajAS13', quantity: 2 }]
之后我想修改所有产品,这样的做法对吗?
我尝试过的:
Product.find({
'_id': { $in: { cart.products } }
}, function(err, product) {
})
});
【问题讨论】:
标签: node.js mongodb mongoose mongoose-schema