Enforce a type mapping with mgo
问题 An _id member is not mapped to type ObjectId anymore, when its type is only derived from bson.ObjectId: import ( "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" ) type CustomId bson.ObjectId type Foo struct { ID1 CustomId `bson:"_id"` // broken ID2 bson.ObjectId // mapped as expected } func main() { session, _ := mgo.Dial("127.0.0.1") coll := session.DB("mgodemo").C("foocoll") doc := Foo{ CustomId(bson.NewObjectId()), bson.NewObjectId(), } coll.Insert(doc) } The _id should have been an ObjectId in