title: node.js and mongodb-native: wait till a collection is non-empty
body: <p>I am using node.js and with the native mongodb driver (node-mongodb-native);</p>
  
  <p>My current project uses node.js + now.js + mongo-db.</p>
  
  <p>The system basically sends data from the browser to node.js, which is processed with haskell and later fed back to the browser again.</p>
  
  <p>Via a form and node.js the text is inserted in a mongo-db collection called "messages".
  A haskell thread reads the entry and stores the result in the db collection "results". This works fine.</p>
  
  <p>But now I need the javascript code that waits for the result to appear in the collection results.</p>
  
  <p>Pseudo code:</p>
  
  <pre><code>   wait until the collection result is non-empty.
     findOne() from the collection results.
     delete the collection results.
  </code></pre>
  
  <p>I currently connect to the mongodb like this:</p>
  
  <pre><code>    var mongo = require('mongodb'),
      Server = mongo.Server,
      Db = mongo.Db;
  
      var server = new Server('localhost', 27017, {
          auto_reconnect: true
      });
      var db = new Db('test', server);
  </code></pre>
  
  <p>My haskell knowledge is quite good but not my javascript skills.
  So I did extensive searches, but I didn't get far.</p>