1 LotteryReceiveRecord.find({"lottery":req.params.id}).populate("user lottery").exec(function(err,result){ 2 _.each(result, function(r) { 3 _.each(item.prizes, function(p) { 4 if(r.prize == p.id) r.order = p.order; 5 }); 6 }); 7
8 cb(null,result); 9 });
簡化後:segmentfault
LotteryReceiveRecord.find({"lottery":req.params.id}).populate("user lottery").exec(function(err,result){ console.log(result) });
此時查詢帶有populate,查詢出的數據,引用的文檔會所有打出,如果沒有populate,引用文檔打印出來的都是ID字符串,須要打印哪一項,就將哪一項添加到populate的參數中,spa
注意書寫格式;如有N個參數,用空格隔開,還有其餘的一些用法參數,暫時不須要,這裏就不在贅述,code
相關文章blog