These are chat archives for Automattic/mongoose

26th
Nov 2017
scare4face
@scare4face
Nov 26 2017 08:23 UTC
trying to post two different data to the view on the same route. is this correct?
app.get('/', function(req, res, next){ //customers route

        customerCol.find({}, (err, data) =>{
            if (err) throw err;
            res.render('home', {customers: data});
            next();
        });
    // prices route
    },  function(req, res){

                pricesCol.find({}, (err, data)=>{
                    if (err) throw err;
                    res.render('home', {prices: data});
                });

     });// '/' route end
Paul "Joey" Clark
@joeytwiddle
Nov 26 2017 14:11 UTC

@scare4face That doesn't look right to me. Wouldn't that add two <body>s ?

I suggest passing both bits of data to the view in one go. And why not use promises too!

customerCol.find({}).then(customerData => {
  return pricesCol.find({}).then(pricesData => {
    res.render('home', {customers: customerData, prices: pricesData});
    next();
  });
}).catch(error => {
  next(error);
});