Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKrystal Jackson
8,598 PointsQuick question about using data from mongo in a webpage.
Say a had a list of games with their date and location and I wanted to display that information as a table on a webpage. How can I access the information from my mongo database so I can use it on my webpage?
Also I tried to go to the documentation but there are many categories to click and I think I'm clicking the wrong one. If you know which section I should click that would help as well.
2 Answers
Oliver Statt
5,175 Pointsuse the mongoose .find() method: Game.find({}, {date: true, location: true, _id: false}, (err, documents) => { // documents contains ur data res.render('renderpage', {games: documents}); // something like that, then use pug to make table with it // you could also save the data somewhere on the req object, e.g.: req.params.gameData = documents. // and then call next() and use the data later. (depending on where in ur program u use the .find method, maybe u have next and req. });
Erika Suzuki
20,299 PointsI believe if you watch the next videos, it will be thought to use. The whole CRUD stuff.