Search code examples
node.jsexpressmongoosemeanjs

Unable to find record by id in mongoose


I am trying to find record by id but it not getting done

var id = req.param('id');
var item = {
    '_id': id
}
videos.find(item, function(error, response) {});

I have give a valid id but still it is not fetching,can anyone suggest help,please.


Solution

  • There is a callback provided to find() but in your code above, it has no executable statements. Instead of this:

    videos.find(item, function(error, response) {});
    

    ...do something like this:

    videos.find(item, function(error, response) {
      if (error) {
        console.log(error); // replace with real error handling
        return;
      }
      console.log(response); // replace with real data handling
    });