草庐IT

totalInvoiced

全部标签

javascript - 如何为 Mongoose 查询中返回的每个文档执行异步方法

我有一个mongoose模型架构,设置如下。varorderSchema=newSchema({_invoices:[{type:Schema.ObjectId,ref:'invoice'},_discounts:[{type:Schema.ObjectId,ref:'discount'},_client:String});orderSchema.methods.totalInvoiced=function(cb){this.populate('_invoices',function(err,order){cb(err,_.reduce(_.pluck(order._invoices,