package main import ( "fmt" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" "log" ) type Person struct { Name string Phone string } func main() { session, err := mgo.Dial("localhost:27017") if err != nil { panic(err) } defer session.Close() session.SetMode(mgo.Monotonic, true) c := session.DB("test").C("people") //err = c.Insert(&Person{"superWang", "13478808311"}, // &Person{"David", "15040268074"}) //if err != nil { // log.Fatal(err) //} result := Person{} err = c.Find(bson.M{"name": "superWang"}).One(&result) if err != nil { log.Fatal(err) } fmt.Println( result) }
问题: golang操作mongodb,
err = c.Find(bson.M{"name": "superWang"}).One(&result)
我想查找一条数据,必须传入一个指针接收,&result封装了什么字段,就会返回什么字段,我就是想像python一样把整条json返回回来不行吗?