title: python + pymongo: how to insert a new field on an existing document in mongo from a for loop
body: <p>I'm using a for loop in python to loop over the result of a query with pymongo. Here is the code:</p>
  
  <pre><code>from pymongo import MongoClient
  connection = MongoClient()
  db = connection.Test
  
  myDocs = db.Docs.find( { "geolocCountry" : { "$exists" : False } } )
  
  for b in myDrives:
      my_lat = b['TheGpsLog'][0]['latitude']
      my_long = b['TheGpsLog'][0]['longitude']
  
      myGeolocCountry = DoReverseGeocode(lat_start,long_start) 
      #    Here I perform a reverse geocoding, it does not matter for this example. 
      #    The important thing is: it returns a string, like 'US', 'UK', etc...
  </code></pre>
  
  <p>The question I have is, how can I insert the variable <code>myGeolocCountry</code> into the non existing field <code>geolocCountry</code> on the existing document (<code>b</code>)? </p>
  
  <p>I tried with </p>
  
  <pre><code>b['geolocCountry'] = myGeolocCountry
  </code></pre>
  
  <p>but it didn't work at all, it does not even produce an error. </p>
  
  <p>Thanks</p>