doushih06137 2013-01-29 18:38
浏览 60

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

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: ""' at the end of the People []Person line

  • 写回答

1条回答 默认 最新

  • doumeng3080 2013-02-06 17:38
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)