javascript - Mongo嵌套字段填充问题
问题描述
var buyerSchema = new Schema({
cart: [{
id: {
type: Schema.Types.ObjectId,
ref: "product"
},
number: Number
}],
personName: { type: String, required: true, trim: true },
image: { type: String, required: false, trim: true },
email: { type: String, required: true, trim: true }
})
我如何填充 Id 字段
buyerMdl.findByToken(buyer['token']).populate({path: 'cart', populate: {path : 'id', model : 'product'}})
这个特定的命令对我不起作用
解决方案
你id
在卡片数组里面......所以你应该使用点符号来填充id
buyerMdl.findByToken(buyer['token']).populate({ path: 'cart.id' })