Search code examples
javascriptnode.jsmongodbexpressmonk

MongoDB findById not working


I'm using Monk and MongoDB to try and get a record by ID populate through the request params but it returns nothing.

I've tried lots of the suggestions on SO but nothing is working, does anyone have any ideas where I'm going wrong?

Here is my code:

router.get('/:id', function(req, res) {
  var db = req.db;
  var collection = db.get('bugs');
  collection.findById(req.params.id, {}, function(e,docs){
      res.render('bug', { 'bug': docs });
  });
});

And I'm trying to access by going to localhost:3000/bugs/recordidstring

Thanks


Solution

  • I was being an utter idiot and when I was connecting to the DB I was connecting to the wrong one!

    Sorry guys, my bad!