I want to find news from mongodb and then extend them with a key 'normal'
News.find().sort({date:-1}).exec(function(err, results) {
if (err) return next(err);
results.map(function(news) {
news.normal = {
title : news.title,
description : news.description,
content : news.content,
image : news.image
}
return news
})
res.json(results);
but this gives me news without this key. What i am doing wrong?
I think its because you are not assigning the result of the map back to the results variable.
In other words - you were missing the 'results = ' part of 'results = results.map(fn(){})'
News.find().sort({date:-1}).exec(function(err, results) {
if (err) return next(err);
results = results.map(function(news) {
news.normal = {
title : news.title,
description : news.description,
content : news.content,
image : news.image
}
return news
})
res.json(results);