Send multiple collections to one ejs file using mongodb and nodejs Send multiple collections to one ejs file using mongodb and nodejs mongoose mongoose

Send multiple collections to one ejs file using mongodb and nodejs


In your get response you should render only once the index page passing the parameters all together.

    app.get('/index', function(req, res){                    Activities.find({}, function(err, activity){          if(err){              console.log(err);          }else{                  Upcoming.find({}, function(err, upcomingActivity){          if(err){              console.log(err);          }else{              res.render('index', {activity:activity, upcoming:upcomingActivity,});          }        });          }        });    });

It will work this way, since you have only a few collections but other way to do so is passing it as a global object and then rendering it.