title: Golang MGO - Insert or update not working as expected
body: <p>I'm running a website in Go and I'm using the <a href="https://labix.org/mgo" rel="noreferrer">MGO</a> package to connect with my MongoDB database.</p>
  
  <p>I am handling a user's sign in, and I am trying to use the func <a href="https://godoc.org/gopkg.in/mgo.v2#Collection.Upsert" rel="noreferrer"><code>Upsert()</code></a> to update a user if they exist in the database, otherwise insert them.</p>
  
  <p>The issue is, when I run <a href="https://godoc.org/gopkg.in/mgo.v2#Collection.Upsert" rel="noreferrer"><code>Upsert()</code></a> (the code below), it replaces all fields rather than updating only the present fields in the second argument's <code>bson.M{}</code>.</p>
  
  <pre><code>db.C("users").Upsert(
      bson.M{"email": "someone@gmail.com"}, // Which doucment to upsert
      bson.M{"displayName": "Johhny"}, // What to replace
  )
  </code></pre>
  
  <hr>
  
  <p><strong>A visual example of what I'm trying to explain.</strong></p>
  
  <p>An existing database document:</p>
  
  <pre><code>{
      "_id" : ObjectId("58e7589bab64da55ebcf5d25"),
      "email" : "someone@gmail.com",
      "password" : "",
      "age": 69,
      "displayName" : "Someone!"
  }
  </code></pre>
  
  <p>After running:</p>
  
  <pre><code>db.C("users").Upsert(
      bson.M{"email": "someone@gmail.com"},
      bson.M{"displayName": "My name was updated"},
  )
  </code></pre>
  
  <p>The document becomes:</p>
  
  <pre><code>{
      "_id" : ObjectId("58e789feab64da55ebcf691c"),
      "displayName" : "My name was updated"
  }
  </code></pre>
  
  <p>When I expected the document to become:</p>
  
  <pre><code>{
      "_id" : ObjectId("58e7589bab64da55ebcf5d25"),
      "email" : "someone@gmail.com",
      "password" : "",
      "age": 69,
      "displayName" : "My name was updated" // This should be updated, all others should be left untouched
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Finally my question.</strong></p>
  
  <p>How can I update a document if it already exists in a MongoDB collection, otherwise insert it?</p>