title: Mongodb $unwind aggregation not working
body: <p>I am new to mongodb aggregation. my mongo document have many arrays. I need to export it as a flat file. For that I need structure it. I tried following aggregation:</p>
  
  <pre><code>[
  {$unwind : "$items" },
  {$unwind : "$items.discounts"},    
  {$unwind : "$payments"},
  {$unwind : "$payments.items"},  
  {$unwind : "$payments.refunds"}
  ]
  </code></pre>
  
  <p>It worked, then i just added following condition to filter data</p>
  
  <pre><code>[
  {$match : { "updatedtime": { $gt: 1514764800000}}},
  {$unwind : "$items" },
  {$unwind : "$items.discounts"},    
  {$unwind : "$payments"},
  {$unwind : "$payments.items"},  
  {$unwind : "$payments.refunds"}
  ]
  </code></pre>
  
  <p>returns 0 rows, I tried again with match statement alone</p>
  
  <pre><code>[
  {$match : { "updatedtime": { $gt: 1514764800000}}}
  ]
  </code></pre>
  
  <p>It Works again.</p>
  
  <pre><code>[
  {$match : { "updatedtime": { $gt: 1514764800000}}},
  {$unwind : "$items" }
  ]
  </code></pre>
  
  <p>Works.</p>
  
  <pre><code>[
  {$match : { "updatedtime": { $gt: 1514764800000}}},
  {$unwind : "$items" },
  {$unwind : "$items.discounts"}
  ]
  </code></pre>
  
  <p>Not working. Can any one tell me is am doing something wrong. Is there any other way to do this?</p>