title: Iterating through all documents or objects in MongoDB
body: <p>What is the command for displaying the n-th object/document in MongoDB? </p>
  
  <p>Say I have 4000 objects stored in the database, and I want to loop through all 4000 of these objects to apply commands to them, I would do something like this:</p>
  
  <pre><code>for(i=0;db.foo.count();i++){
      do something
  }
  </code></pre>
  
  <p>What should <code>i</code> be, with <code>i</code> being the first index. How do I iterate through all objects in MongoDB?</p>