【发布时间】:2021-01-29 12:50:23
【问题描述】:
我知道我可以在没有 _id 的情况下在 mongoose 中使用 virtual 来填充。 但是我的情况是这样的:
const storeSchema = new mongoose.Schema({
store_id: Number,
store_name: String,
cart_tokens: [String],
})
const cartSchema = new mongoose.Schema({
cart_token: String,
items: { type: Array },
})
我在 store 模式中的 cart_tokens 是一个数组而不是一个值。 我希望 store 的结果是这样的:
{
store_id: xxx,
store_name: xxx,
carts:[
{
cart_token: xxx,
items: [...],
},
{...},
{...}
]
}
可以这样做吗?
【问题讨论】:
标签: node.js mongodb mongoose populate mongoose-populate