title: Nodejs function returns before internal function completes
body: <p>I am trying to return whether a user already exists in a MongoDB. Running <code>console.log</code> within <code>collection.find()</code> prints the correct amount (greater than 0). However, when <code>userExists</code> is called, it always returns <code>false</code> (0).</p>
  
  <p>How do I make Javascript wait for these functions to complete before returning a value? I've read about jQuery's <code>$.Deffered()</code>, but this feels dirty to me, and it didn't work.</p>
  
  <pre><code>function userExists(db, uid){
      var collection = db.get('users');
      var ret = 0;
  
      collection.find({"uid":uid},{},function(e,docs){
          ret = docs.length
      });
  
      return ret &gt; 0?true:false;
  }
  </code></pre>