title: Get the size of an array of each document in a sub array
body: <p>I've a document in the collection 'gyms' which looks like the following:</p>
  
  <pre><code> "name" : "Testing",
   "albums" : [ 
      {
          "name" : "Aerobics",
          "photos" : [ 
              {
                  "filepath" : "aerobics.jpg"
              }
          ]
      }, 
      {
          "name" : "Aqua",
          "photos" : [ 
              {
                  "filepath" : "aqua.jpg"
              }
          ]
      }, 
      {
          "name" : "Zumba",
          "photos" : [ 
              {
                  "filepath" : "zumba.jpg"
              }
          ]
      }
  ],
  </code></pre>
  
  <p>I'd like to select the amount of photos from each album into the projection.</p>
  
  <p>So my output would look like the following:</p>
  
  <pre><code> "name" : "Testing",
   "albums" : [ 
      {
          "name" : "Aerobics",
          "amount_photos" : 1,
          "photos" : [ 
              {
                  "filepath" : "aerobics.jpg"
              }
          ]
      }, 
      {
          "name" : "Aqua",
          "amount_photos" : 1,
          "photos" : [ 
              {
                  "filepath" : "aqua.jpg"
              }
          ]
      }, 
      {
          "name" : "Zumba",
          "amount_photos" : 1,
          "photos" : [ 
              {
                  "filepath" : "zumba.jpg"
              }
          ]
      }
  ]
  </code></pre>
  
  <p>It should be achievable with aggregation but i'm getting the following error when I try my query: </p>
  
  <blockquote>
    <p>The argument to $size must be an Array, but was of type: String</p>
  </blockquote>
  
  <p>Query:</p>
  
  <pre><code> db.gyms.aggregate(
     [
        {
           $project: {
              'albums.photos' : {
                 amountPhotos: { $size: "photos" } 
              }
           }
        }
     ]
  )
  </code></pre>