title: MongoDB: aggregation - group condition if not empty
body: <p>If have data like this:</p>
  
  <pre><code>{
   user: "max",
   uploaded: &lt;timestamp&gt;,
   updated: &lt;timestamp&gt;
  }
  {
   user: "tim",
   uploaded: &lt;timestamp&gt;
  }
  </code></pre>
  
  <p>Ever user can have different Items. Now I use the mongoDB aggregation framework with $match + $group like this:</p>
  
  <pre><code>aggregate([
  { $match: {"username": "foouser"}},
  { $group: {
    ...other items..
    "last_active": max(updated) OR IF EMPTY max(uploaded)
  }
  ]);
  </code></pre>
  
  <p>I want to set "last_active" to the max timestamp of updated so get the last active of a User over all his items. But not every item has a update-property. Maybe there is on update-property in any element of a user. So if max(updated) is empty he should pick max(uploaded).</p>
  
  <p>Can anyone help me with this condition in a group-order?</p>