我正在尝试检索填充此类的对象:
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 []Person 行末添加 'bson: ""' 即可。