So, I'm using mongojs. To get values into a rendered view, it was my understanding that one had to do something like this:
app.get('/someurl', function(req, res) {
db.mymongocollection.find(function(err, docs) {
//console.log(docs[0].First);
res.render('someview',{first: docs[0].First});
});
});
What if I wanted to move a ton of data to my view? Like the first names and last names for 20 people, but only if they play soccer? I understand that I can change the query parameters (to account for things such as only plating soccer), but is there a way to loop through the docs index somehow? So I don't have to hardcode something like:
res.render('someview',{first1:docs[0].Name, first2:docs[2].Name .....});
You can just pass the array of documents to your template:
app.get('/someurl', function(req, res) {
db.mymongocollection.find(function(err, docs) {
res.render('someview', { docs : docs });
});
});
And in your template, loop through it:
for doc in docs:
h1 #{doc.First} #{doc.Last}