title: Doctrine ODM: Embedding multiple GridFS documents exception
body: <p>I'm trying to embed a thumbnail image inside of it's main larger image in GridFS via Doctrine / Symfony 2.</p>
  
  <p>The main image document is as follows,</p>
  
  <pre><code>&lt;?php 
  
  namespace namespace\goes\here\Document;
  
  use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
  
  /**
   * @MongoDB\Document
   */
  class FullSizeImage
  {
  
      /** @MongoDB\Id */
      private $id;
  
      /** @MongoDB\File */
      private $file;
  
      /** @MongoDB\String */
      private $filename;
  
      /** @MongoDB\String */
      private $mimeType;
  
      /** @MongoDB\Date */
      private $uploadDate;
  
      /** @MongoDB\Int */
      private $userId;
  
      /** @MongoDB\Int */
      private $length;
  
      /** @MongoDB\Int */
      private $chunkSize;
  
      /** @MongoDB\String */
      private $md5;
  
      /** @MongoDB\Collection */
      private $tags = array();
  
      /** @MongoDB\EmbedOne(targetDocument="Thumbnail") */
      private $thumbnail;
  
      public function getId()
      {
          return $this-&gt;id;
      }
  
      public function setId($id)
      {
          $this-&gt;id = $id;
      }
  
      public function getTags()
      {
          return $this-&gt;tags;
      }
  
      public function setTags($tags)
      {
          $this-&gt;tags = $tags;
      }
  
      public function getFile()
      {
          return $this-&gt;file;
      }
  
      public function setFile($file)
      {
          $this-&gt;file = $file;
      }
  
      public function getFilename()
      {
          return $this-&gt;filename;
      }
  
      public function setFilename($filename)
      {
          $this-&gt;filename = $filename;
      }
  
      public function getMimeType()
      {
          return $this-&gt;mimeType;
      }
  
      public function setMimeType($mimeType)
      {
          $this-&gt;mimeType = $mimeType;
      }
  
      public function getChunkSize()
      {
          return $this-&gt;chunkSize;
      }
  
      public function getLength()
      {
          return $this-&gt;length;
      }
  
      public function getMd5()
      {
          return $this-&gt;md5;
      }
  
      public function getUploadDate()
      {
          return $this-&gt;uploadDate;
      }
  
      public function getUserId()
      {
          return $this-&gt;userId;
      }
  
      public function setUserId($userId)
      {
          $this-&gt;userId = $userId;
      }
  
      public function getThumbnail()
      {
          return $this-&gt;thumbnail;
      }
  
      public function setThumbnail($thumbnail)
      {
          $this-&gt;thumbnail = $thumbnail;
      }
  
  }
  </code></pre>
  
  <p>and the thumbnail document, that lives under the same namespace, is as follows,</p>
  
  <pre><code>&lt;?php
  
  namespace namespace\goes\here\Document;
  
  use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
  
  /** @MongoDB\EmbeddedDocument */
  class Thumbnail
  {
  
      /** @MongoDB\Id */
      private $id;
  
      /** @MongoDB\File */
      private $file;
  
      /** @MongoDB\String */
      private $filename;
  
      /** @MongoDB\String */
      private $mimeType;
  
      /** @MongoDB\Date */
      private $uploadDate;
  
      /** @MongoDB\Int */
      private $length;
  
      /** @MongoDB\Int */
      private $chunkSize;
  
      /** @MongoDB\String */
      private $md5;
  
      public function getId()
      {
          return $this-&gt;id;
      }
  
      public function setId($id)
      {
          $this-&gt;id = $id;
      }
  
      public function getFile()
      {
          return $this-&gt;file;
      }
  
      public function setFile($file)
      {
          $this-&gt;file = $file;
      }
  
      public function getFilename()
      {
          return $this-&gt;filename;
      }
  
      public function setFilename($filename)
      {
          $this-&gt;filename = $filename;
      }
  
      public function getMimeType()
      {
          return $this-&gt;mimeType;
      }
  
      public function setMimeType($mimeType)
      {
          $this-&gt;mimeType = $mimeType;
      }
  
      public function getChunkSize()
      {
          return $this-&gt;chunkSize;
      }
  
      public function getLength()
      {
          return $this-&gt;length;
      }
  
      public function getMd5()
      {
          return $this-&gt;md5;
      }
  
      public function getUploadDate()
      {
          return $this-&gt;uploadDate;
      }
  
  }
  </code></pre>
  
  <p>When I try to persist / flush the <code>FullSizeImage</code>,</p>
  
  <pre><code>$thumbnail = new Thumbnail();
  $thumbnail-&gt;setFile($thumbPath);
  $thumbnail-&gt;setFilename($thumbName);
  $thumbnail-&gt;setMimeType($thumbMimeType);
  $thumbnail-&gt;setUserId($user-&gt;getId());
  
  $fsi = new FullSizeImage();
  $fsi-&gt;setFile($file-&gt;getRealPath());
  $fsi-&gt;setTags(array('tag', 'tag', 'tag'));
  $fsi-&gt;setFilename($file-&gt;getFilename());
  $fsi-&gt;setMimeType($file-&gt;getMimeType());
  $fsi-&gt;setUserId($user-&gt;getId());
  $fsi-&gt;setThumbnail($thumbnail);
  
  $dm-&gt;persist($fsi);
  $dm-&gt;flush();
  </code></pre>
  
  <p>I encounter this exception, </p>
  
  <blockquote>
    <p>Could not store file: zero-length keys are not allowed, did you use $
    with double quotes?</p>
  </blockquote>
  
  <p>Am I missing something? Or is there a better way to go about storing these images and their relationship in mongo?</p>