1

I'm really sorry about this topic. I see many others, but anything could help me to solve my problem.

So, I'm using Go + mgo in my backend and the structure that I have to search for is:

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"`
}

The table "videos" has 2kk+ of information and first, I have to select these videos from his site profile that has stored in this structure:

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"`
}

Then, I'm doing this command to fetch the requests that have same profile, inside a loop of profiles:

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

In the log messages, I'm getting an empty array and doing the same thing using Robomongo, that is node based, I have these rows listed by they site profile normally. So, does anybody know how can I retrieve these data, searching for the nested object?

Thank you for your help!

3
  • please not ignore error return of Find.
    – Jiang YD
    May 16, 2016 at 2:54
  • @JiangYD thanks! I correct these line of code, but, no error has returned! May 16, 2016 at 3:00
  • Try checking mgo logs using these mgo.SetDebug(true) mgo.SetLogger(log.New(os.Stdout,"err",6))
    – Ami
    May 25, 2017 at 9:46

1 Answer 1

0

Well, it is really weird, but when I rewrite the code, verifying the error from the find method, it works. I just did this:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.