title: Querying the total number of elements in nested arrays - embed documents MongoDB
body: <p>I have documents in my collections like to:</p>
  
  <pre><code>{
    _id: 1,
    activities: [
      {
        activity_id: 1,
        travel: [
          {
            point_id: 1,
            location: [-76.0,19.1]
          },
          {
            point_id: 2,
            location: [-77.0,19.3]
          }
        ]
      },
      {
        activity_id: 2,
        travel: [
          {
            point_id: 3,
            location: [-99.3,18.2]
          }
        ]
      }
    ]
  },
  {
    _id: 2,
    activities: [
      {
        activity_id: 3,
        travel: [
          {
            point_id: 4,
            location: [-75.0,11.1]
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p>I can get the total number of activities, as follows:</p>
  
  <pre><code>db.mycollection.aggregate(
    {$unwind: "$activities"}, 
    {$project: {count:{$add:1}}}, 
    {$group: {_id: null, number: {$sum: "$count" }}}
  )
  </code></pre>
  
  <p>I get (3 activities):</p>
  
  <pre><code>{ "result" : [ { "_id" : null, "number" : 3 } ], "ok" : 1 }
  </code></pre>
  
  <p><strong>question:</strong> How can I get the total number of elements in all travels?</p>
  
  <p><strong>expected result:</strong> <code>4</code> elements</p>
  
  <p>these are:</p>
  
  <pre><code>{
    point_id: 1,
    location: [-76.0,19.1]
  },
  {
    point_id: 2,
    location: [-77.0,19.3]
  },
  {
    point_id: 3,
    location: [-99.3,18.2]
  },
  {
    point_id: 4,
    location: [-75.0,11.1]
  }
  </code></pre>