I wrote a simple test program based on the example on the MGO web page and modified it to use some binary data. When I run this, binary data is written into the database but when the record is retrieved the binary data does not get unmarshalled into the struct. The name field is unmarshalled just fine. I am sure I am overlooking something obvious. I noted in the documentation that if the data does not fit the field in the struct then it is "silently skipped" and I thought that might have been the source of my problems but preallocating len and capacity of the byte array in the bson.Binary field did nothing. I would really appreciate it if someone could point out the proper tree for me to start barking up.
package main
import (
"fmt"
)
type Sample struct {
Name string
Bin bson.Binary
}
func main() {
session, err := mgo.Dial("xxxxxxxxxxxxxxxxx")
if err != nil {
panic(err)
}
defer session.Close()
session.SetMode(mgo.Monotonic, true)
c := session.DB("test").C("samples")
err = c.Insert(&Sample{"CoreSample1", bson.Binary{0, []byte("Some random goop")}})
if err != nil {
panic(err)
}
result := Sample{}
err = c.Find(bson.M{"name": "CoreSample1"}).One(&result)
if err != nil {
panic(err)
}
fmt.Println(result)
}