'JavaScript & monk: turn result from find() to array
I am working on an assignment that required us to fetch data of newsfeeds from a MongoDB database using monk. And put them onto a webpage. I am planning to get the data needed in an array. But when I run this, it responses
newsList.find(...).toArray is not a function
I have searched for a solution for that for a while. And I can't really find one.
app.get('/newsfeed.html', function(req, res){
var db = req.db;
var newsList = db.get('newsList');
var newsArray = newsList.find({}, ['-_id', 'headline', 'date', 'content', '-comments']).toArray();
var response = "";
for (let i = 0; i < newsArray.length; i++){
response += newsArray[i];
}
res.send(response);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
