产品架构:
var ProductSchema = new Schema({
productName: {type: String, required: true},
});
客户架构:
var ClientSchema = new Schema({
clientName: {type: String, required: true},
products: [{ type : mongoose.Schema.ObjectId, ref : 'Product'}],
});
如何在关系中添加其他字段?例如,添加字段数量:
var ClientSchema = new Schema({
clientName: {type: String, required: true},
products: [{ type : mongoose.Schema.ObjectId, ref : 'Product', quantity: Number}],
});