title: Golang mongodb mgo driver Upsert / UpsertId documentation
body: <p>The <a href="http://docs.mongodb.org/manual/reference/method/db.collection.update/#db.collection.update" rel="noreferrer">mongodb documentation</a> says:</p>
  
  <p>The fields and values of both the  and  parameters if the  parameter contains only update operator expressions. The update creates a base document from the equality clauses in the  parameter, and then applies the update expressions from the  parameter.</p>
  
  <p>And the <a href="http://godoc.org/gopkg.in/mgo.v2#Collection.Upsert" rel="noreferrer">mgo documentation</a> says:</p>
  
  <p>Upsert finds a single document matching the provided selector document and modifies it according to the update document. If no document matching the selector is found, the update document is applied to the selector document and the result is inserted in the collection.</p>
  
  <p>But if i do an upsert like this:</p>
  
  <pre><code>session.UpsertId(data.Code, data)
  </code></pre>
  
  <p>I end up with an entry which have an ObjectID generated automatically by mongodb, instead of data.Code.</p>
  
  <p>this means that UpsertId expect data to be formated with update operators and you can't use a an arbitrary struct? Or what i'm missing here?</p>
  
  <p>Pd. Mongo 2.4.9 mgo v2 golang go version devel +f613443bb13a</p>
  
  <p>EDIT:</p>
  
  <p>This is a sample of what i mean, using the sample code from Neil Lunn:</p>
  
  <pre><code>package main
  
  import (
    "fmt"
    "gopkg.in/mgo.v2"
    // "gopkg.in/mgo.v2/bson"
  )
  
  type Person struct {
    Code string
    Name  string
  }
  
  func main() {
    session, err := mgo.Dial("admin:admin@localhost");
  
    if err != nil {
          fmt.Println("Error: ", err)
          return
      // panic(err)
    }
  
    defer session.Close()
  
    session.SetMode(mgo.Monotonic, true)
  
    c := session.DB("test").C("people")
  
    var p = Person{
      Code: "1234",
      Name: "Bill",
    }
  
    _, err = c.UpsertId( p.Code, &amp;p )
  
    result := Person{}
    err = c.FindId(p.Code).One(&amp;result)
    if err != nil {
          fmt.Println("FindId Error: ", err)
          return
      // panic(err)
    }
  
    fmt.Println("Person", result)
  
  }
  </code></pre>