Sunday, 23 April 2017

mongoose equivalent to a mongoDB query

I'm following a simple tutorial.

Thing is, I'm using momngoose instead of Mongo. I had no problems until I get to this point:

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

With this, the quotes can be accessed and manipulates on index.ejs

now, I tried doing this:

  app.get('/theroute', (req, res) => {
    MyMongoModel.find()
    .then(documents => {
      res.render('index.ejs', *not entirely sure on what to put here*)
    })
  });

but when I tried to use the documents on the index.ejs page, I got a "not defined" result.

And that's it. No sure on how to google this or what should I do.

Thanks!



via Gonzalo Gutierrez

No comments:

Post a Comment