【发布时间】:2021-10-15 22:33:20
【问题描述】:
假设我有这 2 个模式 具有一系列类别的公司架构
//category
export const CategorySchema = new mongoose.Schema({
name: { type: String },
}, { timestamps: true });
//company
export const CompanySchema = new mongoose.Schema({
user: { type: Schema.Types.ObjectId, ref: 'User' },
name:String,
email:String,
categories:{type: [CategorySchema], default: [] },
}, { timestamps: true });
将类别作为公司类别参考的产品架构
export const ProductSchema =new mongoose.Schema({
name:String,
category:{ type: Schema.Types.ObjectId, ref: 'Category' },
}, { timestamps: true })
是否可以从产品中填充类别? 我试过这段代码,但它不工作
const products=await this.productModel.find({}).populate({'path':"category","model":"Category"}) ``
【问题讨论】:
标签: node.js mongodb mongoose nestjs mongoose-populate