英文:
Using golang's mgo library, how do you retrieve nested objects such as lists
问题
我正在尝试检索填充此类的对象:
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: "<mongodb_class_name>"'
英文:
I am trying to retrieve an object that fills this class:
type Room struct {
Name string
People []Person
Chat []ChatMessage
Me Person
}
The data field "People" comes up as an empty slice []. I am using a simple find to get the data.
result := Room{}
err = c.Find(bson.M{"name": "dev"}).One(&result)
What am I doing wrong?
Figured it out....
The answer can be found here:
https://groups.google.com/d/msg/mgo-users/KirqfCSlKFc/t2l3l4yxFRwJ
Basically, just need to add 'bson: "<mongodb_class_name>"' at the end of the People []Person line
答案1
得分: 6
解决了....
答案可以在这里找到:https://groups.google.com/d/msg/mgo-users/KirqfCSlKFc/t2l3l4yxFRwJ
基本上,只需要在People []Person行的末尾添加'bson: ""'
英文:
Figured it out....
The answer can be found here: https://groups.google.com/d/msg/mgo-users/KirqfCSlKFc/t2l3l4yxFRwJ
Basically, just need to add 'bson: ""' at the end of the People []Person line
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论