title: Simulating an Upsert with mgo.txn
body: <p>Since there's no Upsert in mgo/txn, I'm doing an Insert followed by an Update when I don't know whether a document already exists. Like this (bear in mind this is a simple example, in reality I would also be changing different documents) --</p>
  
  <pre><code>ops := []txn.Op{{
      C:      "test",
      Id:     t.Id,
      Insert: t,
  }, {
      C:      "test",
      Id:     t.Id,
      Update: bson.M{"$set": bson.M{"num": 123}},
  }}
  </code></pre>
  
  <p>This works fine. Unfortunately it requires me to know exactly which fields have been changed. I normally run this inside a Save() function that receives an object and saves a bunch of related documents so I don't usually know what fields have been changed. I tried doing something like this instead --</p>
  
  <pre><code>ops := []txn.Op{{
      C:      "test",
      Id:     t.Id,
      Insert: t,
  }, {
      C:      "test",
      Id:     t.Id,
      Update:t,
  }}
  </code></pre>
  
  <p>But that doesn't seem to work as I get a "Modifiers and non-modifiers cannot be mixed" error. The only solution I came up with was to "$set" every individual field --</p>
  
  <pre><code>ops := []txn.Op{{
      C:      "test",
      Id:     t.Id,
      Insert: t,
  }, {
      C:      "test",
      Id:     t.Id,
      Update: bson.M{"$set": bson.M{"num": 123}},
  }, {
      C:      "test",
      Id:     t.Id,
      Update: bson.M{"$set": bson.M{"other": 234}},
  }}
  </code></pre>
  
  <p>But this seems... clunky. Am I missing something? Is there a way to update the whole document?</p>