gpt4 book ai didi

mongodb - 无法使用 mgo 从 mongodb 检索数据

转载 作者:IT王子 更新时间:2023-10-29 02:23:12 25 4
gpt4 key购买 nike

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

所以,我在后端使用 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 做同样的事情,我通常按站点配置文件列出这些行。那么,有人知道如何检索这些数据,搜索嵌套对象吗?

感谢您的帮助!

最佳答案

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

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

关于mongodb - 无法使用 mgo 从 mongodb 检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37246046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com