无法使用mgo

时间:2016-05-16 02:52:27

标签: mongodb go mgo

我真的很抱歉这个话题。我看到很多其他人,但任何事都可以帮助我解决我的问题。

所以,我在我的后端使用Go + mgo,我必须搜索的结构是:

type Video struct {
    ID           bson.ObjectId `bson:"_id,omitempty"`
    Title        string        `bson:"title"`
    Duration     string        `bson:"duration"`
    Url          string        `bson:"url"`
    DefaultThumb string        `bson:"defaultthumb"`
    SiteID       SiteProfile   `bson:"siteid"`
}

表"视频"有2kk +的信息,首先,我必须从他的网站配置文件中选择这些视频存储在这个结构中:

type SiteProfile struct {
    ID         bson.ObjectId `bson:"_id,omitempty"`
    Name       string        `bson:"name"`
    Site       string        `bson:"site"`
    ExportUrl  string        `bson:"exportUrl"`
    ExportType string        `bson:"exportType"`
}

然后,我执行此命令以在配置文件循环内获取具有相同配置文件的请求:

    var videos []Video
    collVideos.Find(bson.M{"siteid.name": profile.Name}).All(&videos)

在日志消息中,我得到一个空数组并使用Robomongo做同样的事情,这是基于节点的,我通常会按照站点配置文件列出这些行。那么,是否有人知道如何检索这些数据,搜索嵌套对象?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

嗯,这真的很奇怪,但是当我重写代码时,从find方法验证错误,它就可以了。我刚刚这样做了:

    var videos []Video
    err := collVideos.Find(bson.M{"siteid.name": profile.Name}).All(&videos)
    CheckError(err)