title: collection is not defined in mongodb
body: <p>I am trying to get results from mongodb collection but when i call the function through routes it says the error collection is not defined,can any one suggest me help,</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var MongoClient = require('mongodb').MongoClient;
  var url = "mongodb://localhost:27017/mydb";
  MongoClient.connect(url, function(err, db) {
    if(!err) {
      console.log("We are connected");
  
   }});
  
    exports.getprofile = function (url,req, res) {
      collection.find({}).toArray(function(err,res, docs) {
      if(err){
        res.send(err);
      }else if(res.length){
        console.log(res)
        }
        else{
          console.log('no docs found');
        }
      res.send(res);
    });
  }
  </code></pre>