title: Mongodb, find if a collection is empty, node.js
body: <p>I am new to node.js, and heroku, I built a small app that uses node.js and retrieves some data from a mongodb instance. I setup the whole thing but my problem is I think a simple syntactical issue with mongodb.</p>
  
  <p>I need to know on starting the app that my collection has any stuff in it or not, if not, than initialize it. I tried calling collection.count() but returns undefined. </p>
  
  <p>I tried doing this </p>
  
  <pre><code>mongo.connect(mongoUri, {}, function(err, database) {
    if(!err) {
        db = database;
        console.log("Connected to 'testdb' database, HERE");
        db.collection('tests', {safe:true}, function(err, collection) {
            if (err) {
                console.log("The 'tests' collection doesn't exist. Creating it ");
                populateDB();//This would work for the first time I install the app on heroku
            }
            else { //Collection exists, but nothing is in it, this is where I am lost
               console.log("now I am HERE");
               //I do not know how to mimic this piece of code
               //if((collection("tests").find().toArray.size() == 0 or empty or the equivalent of it) {
               //    populateDB();
               //}
               console.log((collection("tests").find().toArray.size()));
            }
        });
    }
    else {
        console.log("COULD NOT CONNECT TO MONGO: " + mongoUri);
    }
  });
  </code></pre>
  
  <p>any help is appreciated.</p>