title: Cannot read property 'insert' of undefined
body: <p>This is my first Node.js program using the Mongo db. This is my code:</p>
  
  <p>/**
   * Module dependencies.
   */</p>
  
  <pre><code> var express = require('express')
   , routes = require('./routes')
   , user = require('./routes/user')
   , http = require('http')
   , path = require('path');
   var mongo = require("./routes/mongo");
   var session = require('express-session');
   var MongoClient = require('mongodb').MongoClient;
   var assert = require('assert');
  
   var monStore=require("connect-mongo")(session);
   var url = 'mongodb://localhost:27017/session';
  
  
   var app = express();
  
   app.configure(function(){
     app.set('port', process.env.PORT || 4000);
     app.set('views', __dirname + '/views');
     app.set('view engine', 'ejs');
     app.use(express.favicon());
     app.use(express.logger('dev'));
     app.use(express.bodyParser());
     app.use(express.methodOverride());
     app.use(app.router);
     app.use(express.static(path.join(__dirname, 'public')));
   });
  
   app.configure('development', function(){
     app.use(express.errorHandler());
   });
  
   app.get('/', routes.index);
   app.get('/users', user.list);
   app.post('/signup',function(req,res){
  var email=req.param("email");
  var fname=req.param("firstname");
  var lname=req.param("lastname");
  var password=req.param("password");
  var url1="mongodb://localhost:27017/signup";
  mongo.connect(url1, function(){
  var db= mongo.collection('user');
  
  db.user.insert({"username": email,
                  "password":password,
                  "firstname":fname,
                  "lastname":lname});
  
  res.render("login",{title:"welcome"});
   });
   });
  
   app.post('/login',function(req,res){
      var email=req.param("email");
  var password=req.param("password");
  var url1="mongodb://localhost:27017/login";;
  mongo.connect(url1, function(){
  var db= mongo.collection('signup');
  db.findOne({username: email, password:password}, function(err,user){
      console.log(user.email);
      if(user)
          {
          res.render("welcome");
          }
      else
          {
          res.render("login",{title:"ivalid"});
          }
  });
  });
   });
  
   MongoClient.connect(url, function() {
  
    console.log("Connected correctly to server.");
  
  });
   http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
   });
  </code></pre>
  
  <p>i get the error Cannot read property 'insert' of undefined where i am trying to insert values into the database. Am I missing some point here? Can somebody Please help me out?</p>