title: How to update values using pymongo?
body: <p>I've a mongodb collection in this form:</p>
  
  <pre><code>{id=ObjectId(....),key={dictionary of values}}
  where dictionary of values is {'a':'1','b':'2'.....}
  </code></pre>
  
  <p>Let dictionary of values be <code>'d'</code>.
  I need to update the values of the key in the <code>'d'</code>.
  i.e I want to change <code>'a':'1'</code> to <code>'a':'2'</code>
  How can do I this in pymongo?</p>
  
  <p>Code goes something like this:</p>
  
  <pre><code>productData is a collection in mongoDB
  for p in productData.find():
       for k,v in p.iteritems():
           value=v['a']
           value=value+1
           v['a']=value
  </code></pre>
  
  <p>Now reflect the new value in the productData.   </p>
  
  <p>This is what I've tried and it introduces a new key-value pair instead of updating the        </p>
  
  <pre><code>for p in productData.find():
      for k,v in p.iteritems():
           value=v['a']
           value=value+1
           v['a']=value
           productData.update({'_id':mongoId},{"$set":{'d.a':'100'}},upsert=False)
  </code></pre>