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

时间:2013-01-29 18:38:08

标签: go mgo

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

type Room struct {
    Name   string
    People []Person
    Chat   []ChatMessage
    Me     Person
}

数据字段“People”显示为空切片[]。我使用简单的查找来获取数据。

result := Room{}
err = c.Find(bson.M{"name": "dev"}).One(&result)

我做错了什么?

想出来......

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

基本上,只需要在People []人物行的末尾添加'bson:“”'

1 个答案:

答案 0 :(得分:6)

想出来......

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

基本上,只需要在People []人物行的末尾添加'bson:“”'

相关问题