title: Is there a way to upsert a list with a single query?
body: <p>I know this question has been asked before, but that's a different scenario.
  I'd like to have a collection like this:</p>
  
  <pre><code>{
      "_id" : ObjectId("4c28f62cbf8544c60506f11d"),
      "pk": 1,
      "forums": [{
          "pk": 1,
          "thread_count": 10, 
          "post_count": 20,
      }, {
          "pk": 2,
          "thread_count": 5, 
          "post_count": 24,
      }]
  }
  </code></pre>
  
  <p>What I want to do is to upsert a "forum" item, incrementing counters or adding an item if it does not exist.</p>
  
  <p>For example to do something like this (I hope it makes sense):</p>
  
  <pre><code>db.mycollection.update({
      "pk": 3,
      "forums.pk": 2
  }, {
      "$inc": {"forums.$.thread_count": 1},
      "$inc": {"forums.$.post_count": 1},
  }, true)
  </code></pre>
  
  <p>and have:</p>
  
  <pre><code>{
      "_id" : ObjectId("4c28f62cbf8544c60506f11d"),
      "pk": 1,
      "forums": [{
          "pk": 1,
          "thread_count": 10, 
          "post_count": 20,
      }, {
          "pk": 2,
          "thread_count": 5, 
          "post_count": 24,
      }]
  },
  {
      "_id" : ObjectId("4c28f62cbf8544c60506f11e"),
      "pk": 3,
      "forums": [{
          "pk": 2,
          "thread_count": 1, 
          "post_count": 1,
      }]
  }
  </code></pre>
  
  <p>I can surely make it in three steps:</p>
  
  <ol>
  <li>Upsert the whole collection with a new item</li>
  <li>addToSet the forum item to the list</li>
  <li>increment forum item counters with positional operator</li>
  </ol>
  
  <p>That's to say:</p>
  
  <pre><code>db.mycollection.update({pk:3}, {pk:3}, true)
  db.mycollection.update({pk:3}, {$addToSet: {forums: {pk:2}}})
  db.mycollection.update({pk:3, 'forums.pk': 2}, {$inc: {'forums.$.thread_counter': 1, {'forums.$.post_counter': 1}})
  </code></pre>
  
  <p>Are you aware of a more efficient way to do it?
  TIA, Germano</p>