title: Updating a value of dictionary in list of dictionaries in a collection using PyMongo
body: <p>The collection structure that I have is as follows:</p>
  
  <pre><code>defaultdict(
      lambda: {
          '_id' : None,
          'stuff' : [defaultdict(lambda : 0)]
      })
  </code></pre>
  
  <p>I am trying to initialise a list of dictionaries that I'll keep on updating in a way that if a dictionary's key already exists then I'll increase its value by 1 otherwise I'll update the list of dictionary with the new <code>key, value</code> pair. e.g. is the value of <code>stuff</code> is [] and I have come across a value <code>val</code> then the value of <code>stuff</code> will be <code>[{'val' : 1}]</code> and further if I get a value <code>val2</code> then <code>stuff = [{'val' : 1}, {'val2' : 1}]</code> and again if I get <code>val</code>, <code>stuff</code> should be <code>[{'val' : 2}, {'val2' : 1}]</code>.</p>
  
  <p>I tried this:</p>
  
  <pre><code>table.update({'_id' : data['_id']}, \
               {'$inc' : {"stuff.$."+keyvalue : 1}})
  </code></pre>
  
  <p>where, <code>data</code> is a JSON object having an <code>_id</code> and a list of dictionaries <code>stuff</code>. Running this I received an <code>OperationFailure: The positional operator did not find the match needed from the query</code>.</p>
  
  <p>I cannot figure out what to do? I am a Mongo newbie.</p>