我正在尝试通过订单集合中的businessId属性来填充我的业务订单。我尝试了这个方法,但无法使其正常工作。https://www.npmjs.com/package/mongoose-reverse-populate 你有什么建议或其他实现方法吗?请帮我检查一下我做错了什么。
Business.findById(id).exec(function(err, business) {
var opts = {
modelArray: business,
storeWhere: "orders",
arrayPop: true,
mongooseModel: Order,
idField: "businessId"
};
reversePopulate(opts, function(err, businessAndOrders) {
req.business = businessAndOrders;
next();
});
});
--
var BusinessSchema = new Schema({
businessName:{
type:String
}
/*.......*/
});
var OrderSchema = new Schema({
data: {
type: String,
}
created: {
type: Date,
default: Date.now
},
businessId: {
type: Schema.ObjectId,
ref: 'Business'
}
});