我用Go编写代码以从指定键获取值,但是它仅返回`_idà值 从我的代码
func main() {
mongoDialInfo := &mgo.DialInfo{
Addrs: []string{"localhost:27017"},
Database: "person",
Username: "user",
Password: "user",
Timeout: 60 * time.Second,
}
session, err := mgo.DialWithInfo(mongoDialInfo)
if err != nil {
panic(err)
}
defer session.Close()
c := session.DB("person").C("person")
result := Person{}
name := "Bill"
err = c.Find(bson.M{"name": name}).Select(bson.M{"surname": 1 }).One(&result)
if err != nil {
panic(err)
}
fmt.Println("Surname is ", result)
}
,代码结果为
{ObjectIdHex(“ 5b9bb0b39b5c3e5733e1c8f7”)}
请帮助我修复它。