I want to select a subdocument using mgo. Before select, the query should query the right top level document. I tried this:
name := "anything"
w := models.Wallet{}
c := s.DB("ep2").C("users")
err := c.Find(bson.M{"name": name}).Select(bson.M{"wallet": 1}).One(&w)
These are the structs:
type User struct {
Id bson.ObjectId `bson:"_id,omitempty" json:"-" form:"-"`
Wallet Wallet `bson:"wallet,omitempty" json:"wallet,omitempty" form:"wallet,omitempty"`
}
type Wallet struct {
Taddr string `json:"taddr,omitempty" form:"taddr,omitempty"`
TaddrPriv string `json:"-" form:"-"`
Tbalance float64 `json:"tbalance" form:"tbalance,omitempty"`
}
It returns an empty wallet document.