【发布时间】:2017-12-23 11:28:46
【问题描述】:
我有 2 个产品系列和产品价格系列。在产品集合中,有一个名为product_id 的字段在字符串中,相同的字段在productprice 集合中,与字符串同名。
如何为此决定 Schema 以及如何填充带有 productprice 字段的产品?
产品字段:_id,Product_id,name
产品价格字段:
_id,Product_id,price
两个集合的Product_id 中的值相同。
const productpriceSchema = mongoose.Schema({
Product_id: {
type: mongoose.Schema.ObjectID,
ref: 'Product'
},
price: String
});
const productSchema = mongoose.Schema({
Product_Name: type: String,
User_Object_ID :type: String,
cid :type: String
});
const Product = module.exports = mongoose.model('Product', productSchema);
const Productprice = module.exports = mongoose.model('Product_price', productpriceSchema);
module.exports.productwithprice = function(callback,limit){
Productprice.find({}, callback).populate('Product_id')
}
【问题讨论】: