title: How do I loop through collections in Mongoose
body: <p>I am trying to loop through all the collections in the underlying connection in Mongoose:</p>
  
  <pre><code>var chai = require('chai'),
      expect = chai.expect,
      mongoose = require('mongoose'),
      db = mongoose.connection;
  
  describe('Blog Tests', function () {
  
      before(function () {
          console.log('before called');
          db.on('error', console.error);
  
          mongoose.connect('mongodb://localhost/mydb', function(err){
              if(err)console.err(err);
  
              // never loops through collections at this point!
              for (var i in mongoose.connection.collections) {
                  console.log(mongoose.connection.collections[i]);
                  // will drop collection here
              }
          });
      });
  
      after(function(){
          console.log('after called');
          if(db.db._state === 'connected'){
              console.log('closing db');
              db.close();
          }
      });
  
      it('Can add a blog post', function (done) {
          db.on('open', function(){
              var blogPostSchema = new mongoose.Schema({
                      id: mongoose.Schema.ObjectId,
                      title: {type: String, required: true},
                      content: {type: String},
                      tags: []
                  }),
                  BlogPost = mongoose.model('BlogPost', blogPostSchema),
                  blogPost = new BlogPost({
                      title: 'Hello World',
                      content: 'Lorem baby',
                      tags: [{"tag": "tests"},{"tag": "mocha"}, {"tag": "chai"}]
                  });
  
              blogPost.save(function(err, saved){
                  if (err) console.error(err);
                  expect(saved.title).is.equal('Hello World');
                  done();
              });
          });
      });
  });
  </code></pre>
  
  <p>Yet it never returns the collection - and they defs exist, it just returns an empty object; not an empty array.</p>
  
  <p>Can anyone spot the silly mistake?</p>
  
  <p>UPDATED as per Gergo suggestion, but still not showing the collections:</p>
  
  <pre><code>var chai = require('chai'),
      expect = chai.expect,
      mongoose = require('mongoose'),
      db = mongoose.connection;
  
  describe('Blog Tests', function () {
  
      before(function (done) {
          console.log('before called');
          db.on('error', console.error);
  
          mongoose.connect('mongodb://localhost/mydb', function(err){
              if(err) return console.err(err);
  
              // never loops through collections at this point!
              for (var i in mongoose.connection.collections) {
                  console.log(mongoose.connection.collections[i]);
                  // will drop collection here
              }
              done();
          });
      });
  
      after(function(done){
          console.log('after called');
          if(db.db._state === 'connected'){
              console.log('closing db');
              db.close();
              done();
          }
      });
  
      it('Can add a blog post', function (done) {
              var blogPostSchema = new mongoose.Schema({
                      id: mongoose.Schema.ObjectId,
                      title: {type: String, required: true},
                      content: {type: String},
                      tags: []
                  }),
                  BlogPost = mongoose.model('BlogPost', blogPostSchema),
                  blogPost = new BlogPost({
                      title: 'Hello World',
                      content: 'Lorem baby',
                      tags: [{"tag": "tests"},{"tag": "mocha"}, {"tag": "chai"}]
                  });
  
              blogPost.save(function(err, saved){
                  if (err) console.error(err);
                  expect(saved.title).is.equal('Hello World');
                  done();
              });
      });
  });
  </code></pre>