title: Mongodb querying nested objects
body: <p>My Object is like,</p>
  
  <pre><code>{
     "Team-A": {
          "captain": "A",
          "homeGround": "some ground",
          "winLoss": "12-4-0"
      },
      "Team-B": {
          "captain": "B",
          "homeGround": "some ground 2",
          "winLoss": "4-4-4"
      }
  }
  </code></pre>
  
  <p>I need to display this information as,</p>
  
  <pre><code>&lt;h1&gt;Team-A&lt;/h1&gt;
  &lt;h2&gt;some ground&lt;/h2&gt;
  &lt;h3&gt;12-4-0&lt;/h3&gt;
  
  &lt;h1&gt;Team-B&lt;/h1&gt;
  &lt;h2&gt;some ground2&lt;/h2&gt;
  &lt;h3&gt;4-4-4&lt;/h3&gt;
  </code></pre>
  
  <p><strong>Nodejs:</strong></p>
  
  <pre><code>MongoClient.connect("mongodb://localhost:27017/MY_DB_TEST", function(err, db) {
        if(!err) {
          console.log("We are connected");        
  
          var collection =  db.collection('football_teams');      
          var stream = collection.find().stream();
  
          stream.on("data", function(item){
              console.log(item);
              res.render('index', {obj: item });
          });     
        }
      });
  </code></pre>
  
  <p><strong>Jade:</strong></p>
  
  <pre><code>h1= obj.captain
  h2= obj.homeGround
  h3= obj.winLoss
  </code></pre>
  
  <p>My console output is:</p>
  
  <pre><code>{ _id: 51064fa1e0d5d118b4b29aa0,
    'Team-A': {
          'captain": 'A',
          'homeGround": 'some ground',
          'winLoss': '12-4-0'
      } }
  
  title is not defined
      at eval (eval at &lt;anonymous&gt; (C:\node_modules\jade\lib\jade.js:176:8))
      at exports.compile (C:\node_modules\jade\lib\jade.js:181:12)
      at Object.exports.render (C:\node_modules\jade\lib\jade.js:216:14)
      at View.exports.renderFile [as engine] (C:\node_modules\jade\lib\jade.js:243:13)
      at View.render (C:\node_modules\express\lib\view.js:75:8)
      at Function.app.render (C:\node_modules\express\lib\application.js:503:10)
      at ServerResponse.res.render (C:\node_modules\express\lib\response.js:721:7)
      at CursorStream.exports.index (C:\Users\HFR&amp;D\Desktop\nodemongoexpress\routes\index.js:18:8)
      at CursorStream.EventEmitter.emit (events.js:96:17)
      at CursorStream._onNextObject (C:\Users\HFR&amp;D\Desktop\nodemongoexpress\node_modules\mongodb\lib\mongodb\cursorstream
  </code></pre>
  
  <p>I'm not understanding how I should loop through my object and get the values Team-A/Team-B and their respective details.</p>
  
  <p>How do I achieve this using <code>nodejs</code> and <code>jade</code>.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Say there are 20 teams, my collection will consists of 20 documents. What I want to do is, loop through my collection and display info in the 20 documents as described above.</p>
  
  <ul>
  <li><p>Is my db structure correct? Should I have a different document for each team?</p></li>
  <li><p>If yes, how do I get the title of the documents (team-A, team-B) dynamically while rendering in jade?</p></li>
  </ul>