Pymongo: iterate over all documents in the collection
<p>I am using PyMongo and trying to iterate over (10 millions) documents in my MongoDB collection and just extract a couple of keys: &quot;name&quot; and &quot;address&quot;, then output them to .csv file.</p>
<p>I cannot figure out the right syntax to do it with <code>find().forEach()</code></p>
<p>I was trying workarounds like</p>
<pre><code>cursor = db.myCollection.find({&quot;name&quot;: {$regex: REGEX}})
</code></pre>
<p>where REGEX would match everything - and it resulted in &quot;Killed&quot;.
I also tried</p>
<pre><code>cursor = db.myCollection.find({&quot;name&quot;: {&quot;$exist&quot;: True}})
</code></pre>
<p>but that did not work either.</p>
<p>Any suggestions?</p>