title: Weird scope behavior in node or am I sleeping?
body: <p>My js is as follows,</p>
  
  <pre><code>/*
   * GET home page.
   */
  
  var MongoClient = require('mongodb'); 
  
  exports.index = function(req, res){
      var studentObj = {};
      MongoClient.connect("mongodb://localhost:27017/MY_DB_TEST", function(err, db) {
        if(!err) {
          console.log("We are connected");        
  
          var collection =  db.collection('test');        
          var stream = collection.find().stream();
  
          stream.on("data", function(item){
              studentObj =  item;
          });     
        }
      });
      res.render('index', { title: 'Express', obj: studentObj });
  };
  </code></pre>
  
  <p>I try to render this page with <strong>jade</strong>, my syntax for that is,</p>
  
  <pre><code>h1 Name: #{obj.name}
  </code></pre>
  
  <p>My <strong>JSON</strong>: (fetched from mongodb)</p>
  
  <pre><code>{
    name: "Ron",
    age: 24
  }
  </code></pre>
  
  <p>This does not work, it only works if I keep my studentObj as a global variable i.e after the <code>require</code> statement.</p>
  
  <p>Also, the <code>obj.name</code> is not rendered on first request, only for 2nd request onwards do I get the name property. </p>
  
  <p>Why are these issues happening? am I missing something extremely trivial?</p>