1
我對此主題感到非常抱歉。我看到很多其他人,但任何東西都可以幫助我解決我的問題。無法使用mgo從mongodb中檢索數據
所以,我使用的圍棋+ 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'的錯誤返回。 –
@JiangYD謝謝!我糾正了這些代碼行,但沒有錯誤返回! –
嘗試使用這些mgo.SetDebug檢查mgo日誌(true) \t mgo.SetLogger(log.New(os.Stdout,「err」,6)) –