首页 > 解决方案 > Mongoose 在数组内的对象内填充对象内的对象?

问题描述

你好我的问题是相当困难的。请帮忙。这是我的推车。我正在使用一个让我失败的查询:

interface CartInterface extends Document {
    products: Array<{
        quantity: number,
        productDetails: PopulatedDoc<ProductInterface>
    }>,
}

我使用了这个查询:Cart.findById(req.params.id).populate('products.productDetails')但它是错误的。我需要进入每个数组并找到每个对象

我需要填充所有数组,以便products[index].productDetails

上次我很容易地填充products.productsArray上次我的架构是这样的:

interface CartInterface extends Document {
    productsArray: Array<PopulatedDoc<ProductInterface>>
}

我使用了这个查询: Cart.findById(req.params.id).populate('productsArray')

标签: node.jsmongodbmongoosepopulate

解决方案


推荐阅读