title: Mongodb not working with Nodejs
body: <p>I'm trying to print name and job of people after taking input from via a html form on the browser. The program also allows deletion and update of record through simple links on the same page. The program is, however, not working.<br/> <br/>
  I even tried creating a "newapp" database (created in the server file) and filled it with some dummy values, the program still wont work!<br/></p>
  
  <p>Following is my node.js file</p>
  
  <pre><code>var express= require("express"),
  http= require("http"),
  bodyparser= require('body-parser'),
  mongo= require("mongodb");
  
  var app= express(),
  db= new mongo.Db("newapp", 
                      new mongo.Server("localhost", 27017), 
                      {safe:true}, {auto_reconnect: true}),
  people= db.collection("people");
  
  app.use(bodyparser.urlencoded({extended: true}));
  
  app.get("/", function(req, res){
      people.find().toArray(function(err, docs){
              if(err) 
                  throw err;
              res.render("index.jade", {people: docs});   
      });
  });
  
  app.post("/", function(req, res){
      people.insert({name: req.body.name, job: req.body.job}, 
              function(err, doc){
                      if(err)
                          throw err;
                      res.redirect("/");
              });
  });
  
  app.listen(3000);
  </code></pre>
  
  <p>My index.jade file is:</p>
  
  <pre><code>form(method="POST")
      p Name:
          input(type="text", name="name")
  
      p Job:  
          input(type="text", name="job")
  
      p: button Add
  
  if(typeof(people)!=="undefined")
      ul
              each person in people
                      li
                          h2= person.name+ " ("+ person.job+ ")"
                          p
                              a(href="/update/#{person._id}") Update
                              a(href="/delete/#{person._id}") Delete
  
  else
      p No People
  </code></pre>
  
  <p>Any help is much appreciated. Thanks a lot!</p>