title: How to copy select documents from one collection to another with pymongo?
body: <p>I've been streaming data from twitter into a mongo database. However I found that I hadn't formatted the search incorrectly, so I got data from all over the place instead of the one city I wanted (I find location by checking if the city name comes up in 'location' or 'name' under 'user' in the json).</p>
  <p>I want to copy just the correct documents to a new collection, but I've found it nearly impossible to do in pymongo! I'm using pymongo instead of the shell because I'm using regular expressions to search for the city names(there's a lot of synonyms for it).</p>
  <pre><code>regex=re.compile(&lt;\really long regular expression of city names&gt;)
  </code></pre>
  <p>I've been able to use find() correctly with the regular expressions; it returns just what I'm looking for:</p>
  <pre><code>db.coll.find({'$or':[{'user.location':{'$in':[regex]}},{'user.name':{'in':[regex]}}]})
  </code></pre>
  <p>I just need to copy what it returns into a new collection, but it's proving difficult.</p>
  <p>I tried <a href="https://stackoverflow.com/a/9712776/4130893">this method</a>, trying forEach() to try to copy the documents, using bson wrapping, which I found <a href="https://stackoverflow.com/a/11858943/4130893">here</a>, but it still won't work.</p>
  <pre><code> db.coll.find({'$or':[{'user.location':{'$in':[regex]}},{'user.name':{'in' [regex]}}]})\
  .forEach(bson.Code( '''
  
  function(doc) { 
     db.subset.insert(doc);
  
   }'''))
  </code></pre>
  <p>Specifically, the error I get when I try this is</p>
  <h1>AttributeError: 'Cursor' object has no attribute 'forEach'</h1>
  <p>I have no idea what is wrong or how I can go about fixing this. Anyone able to tell me what I can do to fix this, or a better way to copy documents to a new collection?</p>