Imagine below sample datas:
TestDB
{
"_id": "56caf46a97bbe1b24163ef81",
"age": 40,
"eyeColor": "red"
},
{
"_id": "56caf46a460b1d91a0d882d8",
"age": 29,
"eyeColor": "green"
},
{
"_id": "56caf46afd859790720a2bb8",
"age": 27,
"eyeColor": "brown"
},
I have to render:
- TestDB.eyeColor (red, green, brown)
- The number of TestDB documents (3)
to view page at the sametime.
I'm using express, so I should use res.render('view', {data}).
I tried like that :
app.get('/somePage', function(req, res, next){
TestDB.find({}, function(err, dbs){
res.render('view', {'eyeColor' : dbs.eyeColor })
}).count(function(err, count){
// How can I render this 'count' to view at the sametime?
// If I render at here, I can't use above dbs.eyeColor,
// Same, If I render at above, I can't use count.
// Ok, There is a way to separate find() and count()
// And make a variable and then render with this,
// Should I do like that? I think there must be easy way.
})
});