title: updateOne - filter one field, push or update sub field, add/update counter
body: <p>I want to track tags frequency within a period. How do I update (counter, updateDate) the array if found, otherwise push to field?</p>
  <pre><code>const date = new Date();
  const beginMonth = new Date(date.getFullYear(), date.getMonth(), 1);
     await Tags.updateOne(
          { tag },
          {
              $set: {
                  tag,
                  period: {
                     // should have $cond: [{ $in: [beginMonth, &quot;$period.createDate&quot;] }]
                      $push: {
                          &quot;createDate&quot;: beginMonth,
                          &quot;updateDate&quot;: date,
                          &quot;counter&quot;: 1,
                      }
                  }
              }
          },
          { upsert: true }
      )
  </code></pre>
  <p>it should have a condition to check if <code>{ $in: [beginMonth, &quot;$period.createDate&quot;] }</code> then <code>{$inc: {counter:1}</code> else <code>$push</code>. Also read that <code>upsert</code> cannot be used like this. How do I achieve this?</p>
  <p>example:
  If <code>world</code> tag exists and <code>createDate</code> is in <code>beginMonth</code> (August 1, 2021), then update counter to 2 and updateDate.</p>
  <p>Let <code>food</code> tag does not exists, so it would push <code>createDate</code>,<code>updateDate</code>,<code>counter</code></p>
  <p>Before update:</p>
  <pre><code>{
    tag: 'world',
    period: [{
     createDate: 2021-08-01T00:00:00.000+00:00,
     updateDate:2021-08-28T13:16:58.508+00:00,
     counter:1
    }]
  }
  </code></pre>
  <p>After update:</p>
  <pre><code>[{
        tag: 'world',
        period: [{
         createDate: 2021-08-01T00:00:00.000+00:00,
         updateDate:2021-08-28T14:16:58.508+00:00,
         counter:2
        }]
      }
  {
        tag: 'food',
        period: [{
         createDate: 2021-08-01T00:00:00.000+00:00,
         updateDate:2021-08-28T14:16:58.508+00:00,
         counter:1
        }]
      }]
  </code></pre>
  <p><code>createDate</code> probably bad naming, should be beginningDate. I am trying to tally tag frequency by month and keeping track of latest update for this period.</p>