使用golang的mgo库,如何检索列表等嵌套对象

use*_*376 5 go mgo

我正在尝试检索填充此类的对象:

type Room struct {
    Name   string
    People []Person
    Chat   []ChatMessage
    Me     Person
}
Run Code Online (Sandbox Code Playgroud)

数据字段"People"出现为空切片[].我使用简单的查找来获取数据.

result := Room{}
err = c.Find(bson.M{"name": "dev"}).One(&result)
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

弄清楚了....

答案可以在这里找到:https: //groups.google.com/d/msg/mgo-users/KirqfCSlKFc/t2l3l4yxFRwJ

基本上,只需要在People [] Person行的末尾添加'bson:""'

use*_*376 6

弄清楚了....

答案可以在这里找到:https://groups.google.com/d/msg/mgo-users/KirqfCSlKFc/t2l3l4yxFRwJ

基本上,只需要在People [] Person行的末尾添加'bson:""'