node.js - 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')
解决方案
推荐阅读
- angular - ng2-file-upload 的内部 express 服务器返回 500 错误
- vue.js - 如何检索元素ID vue js
- async-await - 有没有办法等到函数完成?
- regex - 在文本中查找钱的正则表达式
- kubernetes-helm - 使用全局变量时,helm 子图是否依赖于父图?
- angular - 如何使用 *ngFor 编写条件来检查两个值
- json - 我应该如何在 NewtonSoft.Json 序列化的 JSON 配置文件中实现环境变量替换
- asp.net - ASP.NET TargetSchema 用户控制指令
- c - 查找数组中两个数字的目标总和
- macos - ubuntu 和 OSX 上 xattr.h 中函数定义的差异