title: Cannot read property 'collection' of undefined while connecting to mongodb in node.js?
body: <p>I am trying to login from my signin.ejs file,after click on the login button in
    my signin page it shows "Cannot read property collection undefined" what is the 
    problem.</p>
  
  <p>I defined my route like this in app.js:</p>
  
  <pre><code>app.post('/login', routes.dologin);
  </code></pre>
  
  <p>I defined my dologin route in index.js:</p>
  
  <pre><code>exports.dologin = function (req, res) {
  res.locals.session = req.session;
  
  var user = req.body.user;
  db.authenticateUser(user.email, user.password, function     ( err, response) {
  if (err) {
  .......
  
  .......
  } else {
  .......
  
  ........  
  }
  });
  };
  </code></pre>
  
  <p>In my db.js:</p>
  
  <pre><code>var mongo = require('mongoskin'),
  crypto = require('crypto');
  
  module.exports = function (config) {
  
  var USERS_COLLECTION = 'users',
  ORDERS_COLLECTION = 'orders',
  salt = 'supersecretkey',
  db;
  
      authenticateUser: function (emailId, password,         callback) {
      db.collection(USERS_COLLECTION).count({email : emailId,         password: encryptPassword(password)}, function (err,         count) {
      if (err) {
  console.log("error authenticating user: " + err);
  callback(new Error(err));
  } else if (count === 0) {
  callback(new Error("emailid/password did not match"));
  } else {
  callback(null);
  }
  });
  },
      }
  </code></pre>
  
  <p>What is the problem here for getting "Collection undefined"? i think here 
    everything is right... Is there any problem here?tell me..please Thanks.   </p>