title: MongoDB - dont understand how to loop through collections with a cursor
body: <pre><code>advertisers = db.dbname.find( 'my query which returns things correctly' );
  </code></pre>
  
  <p>I realize now that it returns a cursor to the list of collections.</p>
  
  <p>But I am not sure how to loop through them and get each collection.</p>
  
  <p>I want to try something like this:</p>
  
  <pre><code>advertisers.each(function(err, advertiser) {
      console.log(advertiser);
  });
  </code></pre>
  
  <p>But that does not work. But I didn't see from searching online how to make it actually work with simple JavaScript.</p>
  
  <p>Then I have this code:</p>
  
  <pre><code>var item;
  
  if ( advertisers != null )
  {
     while(advertisers.hasNext()) 
     { 
        item = advertisers.next();
     }
  }
  </code></pre>
  
  <p>and it gives this error: <code>SyntaxError: syntax error (shell):1</code></p>
  
  <p>Help much appreciated!</p>
  
  <p>Thanks!</p>