我的架构:
const ProductSchema = new Schema({
Category: String,
Subcategory: String,
Name: String,
Offers: [{ type: ObjectId, ref: "Offer" }]
})
const OfferSchema = new Schema({
Quantity: Number,
Images: [String],
Price: Number,
Size: String,
Color: String
})
我正在查询带有限制和跳过的过滤器优惠的产品。我试过这个:
const products = await ProductSchema.find({ ...someFilter }).populate({
path: "Offers",
match: {
Quantity: { $gt: 2 },
Images: { $exists: true, $ne: [] }
}
}).skip(skip).limit(limit)
而且我只想获取报价长度> 0的文档。但是我得到的文档为空报价。如果我这样过滤:
products.filter(item => item.Offers.length > 0)
我的分页会中断。你能帮助我吗?