【发布时间】:2018-01-08 19:28:49
【问题描述】:
在我的 web 应用程序中,在订购 (SingleOrder) 产品后,客户应检查报价。如果可用,那么我应该将订单添加到 ComboOfferOrder。
在那里,我想检查订单的付款状态。另外,我必须得到整个产品列表。
我在后端的数据库中拥有所有值。但我无法为我的 api 方法填充“SingleOrder”中的任何对象。
我有以下架构。
*User*
{
name : String,
email : Sring,
role : String
}
*BankTransaction*
{
type : String,
transationReference: String,
date : Date,
amount : Number
}
*ComboOfferOrder*
{
customer :{
type :Schema.ObjectId,
ref : 'User'
},
order : {
type :Schema.ObjectId,
ref : 'SingleOrder'
},
productList : [{
type :Schema.ObjectId,
ref : 'Product'
}]
discount : Number,
totalCost : Number,
paymentStatus :String,
deliveryStatus : String
}
*SingleOrder*
{
code: String,
products : {
groceries:[{
type :Schema.ObjectId,
ref : 'Product'
}],
other:[{
type :Schema.ObjectId,
ref : 'Product'
}]
},
billingAddress: String,
deliveryAddress : String,
payment:{
status : String,
transaction :{
type :Schema.ObjectId,
ref : 'BankTransaction'
}
}
}
*Products*
{
name : String,
cost : Number,
expiryDate : Date
}
我的 api
mongoose.model('ComboOfferOrder')
.findOne({
_id: comboOfferOrderId
})
.select('order')
.exec(function(err, comboOfferOrder) {
var paths = [
{path : "payment.status"},
{path : "payment.trasaction"},
{path : "products.groceries"},
{path : "products.other"}
];
mongoose.model('comboOfferOrder').populate(comboOfferOrder.order,paths,function(err, singleOrder) {
if (err) {
return deferred.reject(err);
}
return deferred.resolve(comboOfferOrder.order);
});
});
在结果中,我只得到了“payment.status”、“payment.trasaction”、“products.groceries”、“products.other”的objectIds
请告诉我解决方案。谢谢。
【问题讨论】:
标签: node.js mongodb mongoose populate