Sunday, 2 April 2017

Trying to access 2 tables in express.js

**

Nodejs/Mongodb/Express

**

So ive been playing around with express/node.js/mongodb and still trying to figure this out. Trying to access 2 tables. 1 Which is holding my navigation links/menu names and the other just a random bunch of data to display on the page.

app.get('/domain', (req, res) => {
    db.collection('navigation').find().toArray((err, result) =>{
       if (err) return console.log(err)
       res.render('domain.ejs', {navigation: result})
    })
})

app.get('/domain', (req, res) => {
    db.collection('quotes').find().toArray((err, result) =>{
       if (err) return console.log(err)
       res.render('domain.ejs', {quotes: result}) 
    })
})

Seems that i can load either load 1 or none. If i try to load both at the same time it will give me a "quotes is not defined" error. Guessing this is because its trying to load both tables at the same time?

---------------------------------------------------------------

Picture of error

^ Thats the error



via Dillon Munien

No comments:

Post a Comment