title: How to flatten nested arrays and remove empty arrays only if they are nested using MongoDB aggregation framework?
body: <p>I'm trying to transform my documents as shown below. I've tried using the <code>$unwind</code> operator, then the <code>$group</code> operator combined with the <code>$push</code> operator to re-build the <code>$user_mentions</code> array, but this also pushes all of the empty arrays and I'm back to square one again.</p>
  
  <p>What I start with:</p>
  
  <pre><code>{
    _id: "6222407",
    name: "Chris",
    user_mentions: [
      [],
      [{_id:"963222", name: "Bob"}, {_id:"234324", name: "Fred"}]
    ]
  },
  {
    _id: "34566",
    name: "Tim",
    user_mentions: [
      []
    ]
  },
  {
    _id: "65343",
    name: "Sean",
    user_mentions: [
      [],
      []
    ]
  }
  }
  </code></pre>
  
  <p>What I want:</p>
  
  <pre><code>{
    _id: "6222407",
    name: "Chris",
    user_mentions: [
      {_id:"963222", name: "Bob"}, 
      {_id:"234324", name: "Fred"}]
    ]
  },
  {
    _id: "34566",
    name: "Tim",
    user_mentions: [
  
    ]
  },
  {
    _id: "65343",
    name: "Sean",
    user_mentions: [
  
    ]
  }
  </code></pre>