title: Adding mongoDB document-array-element using Python Eve
body: <p><strong>Background:</strong> (using Eve and Mongo)</p>
  
  <p>I'm working in Python using the <a href="http://python-eve.org" rel="nofollow noreferrer">Eve</a> REST provider library connecting and to a mongoDB to expose a number of REST endpoints from the database. I've  had good luck using Eve so far, but I've run into a problem that might be a bit beyond what Eve can do natively.</p>
  
  <p>My problem is that my mongoDb document format has a field (called "slots"), whose value is a list/array of dictionaries/embedded-documents.  </p>
  
  <p>So the mongoDB document structure is:</p>
  
  <pre><code>{
     blah1: data1,
     blah2: data2,
     ...
     slots: [
         {thing1:data1, thing2:data2},
         {thingX:dataX, thingY:dataY}
     ]
  }
  </code></pre>
  
  <p>I need to add new records (I.E. add pre-populated dictionaries) to the 'slots' list.  </p>
  
  <p>If I imagine doing the insert directly via pymongo it would look like:</p>
  
  <pre><code>mongo.connection = MongoClient()
  mongo.db = mongo.connection['myDB']
  mongo.coll = mongo.db['myCollection']
  
  ...
  
  mongo.coll.update({'_id' : document_id}, 
                    {'$push': { "slot" : {"thing1":"data1","thingX":"dataX"}  }  } )
  </code></pre>
  
  <p>The REST action/URI combo that I would like to do this action is a <code>POST</code> to '_id/slots', e.g. URI of <code>/app/012345678901234567890123/slots</code>.</p>
  
  <p><strong>Problem:</strong> (inserting an element into an array in Eve)</p>
  
  <p>From SO: <a href="https://stackoverflow.com/questions/29659942/how-to-add-to-a-list-type-in-python-eve-without-replacing-old-values">How to add to a list type in Python Eve without replacing old values</a> and <a href="https://github.com/nicolaiarocci/eve/issues/229" rel="nofollow noreferrer">eve project issue</a> it appears Eve doesn't currently support operating on mongoDB embedded documents (or arrays?) unless the entire embedded document is rewritten, and rewriting the whole array is very undesirable in my case.</p>
  
  <hr>
  
  <p>So, assuming its true Eve doesn't have a method to allow inserting of array elements (and given I already have numerous other endpoints working well inside of Eve)...</p>
  
  <hr>
  
  <p>... I'm now looking for a way, inside of an Eve/Flask configuration with multiple working endpoints, to intercept and change Eve's mongoDB write for just this one endpoint.</p>
  
  <p>I know (worst case) I can override the routing of Eve and to completely do the write by hand, but then I would have manage the <code>_updated</code> and hand check &amp; change the documents <code>_etag</code> value, both things I would certainly prefer not to have to write new code for.</p>
  
  <p>I've looked at Eve's <a href="http://python-eve.org/features.html#database-event-hooks" rel="nofollow noreferrer">Datebase event hooks</a> but I don't see a way to modify the database commands that are executed (I can see how to change the <em>data</em>, but not the <em>commands</em>).</p>
  
  <p>Anyone else already solved this problem already? If not any ideas on the most direct path to implement by hand? (hopefully reusing as much of Eve as possible because I do want to continue using Eve for all my (already working) endpoints)</p>