I have an array of Stock objects and try to attach n Report objects to each of the Stock objects:
router.get('/stocks', function (req, res, next) {
Stock.find({}, function (err, stocks) {
if (err) {
next(err)
return
}
async.map(stocks, function (stock, callback) {
Report.find({ 'isin': stock.isin }).sort('-created').limit(10).exec(function (err, reports) {
if (err) {
next(err)
return
}
stock.reports = reports
return callback(null, stock)
})
}, function (err, stocks) {
if (err) {
next(err)
return
}
res.json(stocks)
})
})
})
What I get is the list of stock objects without the reports... What I want is instead the same stocks, but with the additional attribute reports
set.
Most interesting is the fact, that console.log(stock)
before and after the assignment stock.reports = reports
is the same, but console.log(stock.reports)
delivers the actual array of report objects...