title: MongoDB retrieve all documents
body: <p>I'm trying to get all docs from mongoDB, my code looks like this:</p>
  
  <pre><code>MongoClient.connect('mongodb://localhost/catalog', function(err, db) {
      db.open(function(err, db) {
          var cursor = db.collection('products').find(function(err, cursor) {
              cursor.each(function(err, doc) {
                  console.log(doc);
              });     
          });
      });
  });
  </code></pre>
  
  <p>I don't get anything printed out though and I can't figure out where's the problem. If I put a query string (i.e. find({"name":"Samsung note"})) it works fine and returns products.</p>
  
  <p>Where's my mistake?</p>
  
  <p>tnx!</p>
  
  <p>update: something's wrong even when I call for a single product, cursor.count() returns nothing.</p>
  
  <pre><code>db.open(function(err, db) {
          db.collection('products').find({"upc": "027242799219"}, function(err, cursor) {
              var cnt = cursor.count();
              console.log(cnt);     
          });
      });
  </code></pre>
  
  <p>update(take 2): I went to the other mongoDB .find() question and copied code from the answer:</p>
  
  <pre><code>MongoClient.connect('mongodb://localhost/catalog', function(err, db) {
      theDB = db;
  
      db.open(function(err, db) {
          if (err) return console.log('error opening db, err = ', err);
          console.log("db opened!");
          db.collection('products', function(err, collection) {
              if (err) return console.log('error opening users collection, err = ', err);
              collection.find().limit(100).toArray(function(err, results) {
                  if (err) return console.log('error initiating find on users, err = ', err);
                  else    
                      {
                          for(i = 0; i &lt; 100; i++)
                               {
                                   console.log(results[i]);
                               }
                          db.close();
                          console.log("CLOSED");
                      }                         
                  });
              });
          });
      });
  </code></pre>
  
  <p>Now... this prints the result, BUT if I put a breakpoint on console.log or I try to do something with results[i] (such as write it to elastic) the app is unresponsive. I can see in the task manager that it uses more and more CPU/memory without actually hitting my breakpoint. </p>
  
  <p>What the what?</p>