title: Doctrine MongoDB ODM - bug with cascading executeUpsert
body: <p>doctrine/mongodb-odm version 1.0.8</p>
  
  <p>I have a document that uses self-referencing many to many bi-directional relationship. Ininitally I was getting errors telling me I must set up cascade=persist. I did that and now I am getting a very odd doctrine error. My document:</p>
  
  <pre><code>use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
  
  /**
   * @ODM\Document(collection="ledger", repositoryClass="Tng\ExampleBundle\Repository\LedgerRepository")
   */
  class Ledger
  {
      /**
       * @ODM\Id(strategy="AUTO")
       */
      protected $id;
  
      /**
       * If this is a payment, this will link to the debit ledger
       * @ODM\ReferenceMany(
       *      targetDocument="Tng\ExampleBundle\Document\Ledger",
       *      inversedBy="payment",
       *      strategy="addToSet",
       *      cascade={"persist"},
       *      simple=true
       * )
       */
      protected $payment_for;
  
      /**
       * If this is a debit, these are the payments and credits
       * @ODM\ReferenceMany(
       *      targetDocument="Tng\ExampleBundle\Document\Ledger",
       *      mappedBy="payment_for",
       *      strategy="addToSet",
       *      cascade={"persist"},
       *      simple=true
       * )
       */
      protected $payments;
  
      public function __construct()
      {
          $this-&gt;payments = new \Doctrine\Common\Collections\ArrayCollection();
          $this-&gt;payment_for = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
      // all standard getters/setters with:
      public function addPaymentFor(\Tng\ExampleBundle\Document\Ledger $paymentFor)
      {
          $this-&gt;payment_for[] = $paymentFor;
          $paymentFor-&gt;payments[] = $this;
      }
  
      public function removePaymentFor(\Tng\ExampleBundle\Document\Ledger $paymentFor)
      {
          $this-&gt;payment_for-&gt;removeElement($paymentFor);
          $paymentFor-&gt;payments-&gt;removeElement($this);
      }
  }
  </code></pre>
  
  <p>Now when I try to save the cascading records:</p>
  
  <pre><code>$payment-&gt;setPaymentFor($ledger);
  $dm-&gt;persist($payment);
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>Notice: Undefined index: $set</p>
    
    <p>Stack Trace</p>
    
    <ol>
    <li>in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php at line 315   -</li>
    <li>at ErrorHandler ->handleError ('8', 'Undefined index: $set', '/var/www/etc-mongo-tng/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php', '315', array('data' => array(), 'options' => array('upsert' => true))) </li>
    <li>in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php at line 315   +
    at DocumentPersister ->executeUpsert (array(), array()) </li>
    <li>in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php at line 296   +</li>
    <li>at DocumentPersister ->executeUpserts (array()) 
    in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php at line 1189   +</li>
    <li>at UnitOfWork ->executeUpserts (object(ClassMetadata), array('000000005a8560de00007fc48349ed60' => object(Ledger)), array()) 
    in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php at line 425   +</li>
    </ol>
  </blockquote>
  
  <p>It doesn't look like the same bug affects the 1.1.2 branch. If I patch DocumentPersister.php as follows, it all works. Is this is a legitimate bug? Should I make a PR?</p>
  
  <pre><code>private function executeUpsert(array $data, array $options)
  {
      // I added this line
      if (empty($data)) { return; }
      $options['upsert'] = true;
      $criteria = array('_id' =&gt; $data['$set']['_id']);
      unset($data['$set']['_id']);
  </code></pre>