Using the golang mgo library, how do you retrieve nested objects like lists

I am trying to get an object populating this class:

type Room struct {
    Name   string
    People []Person
    Chat   []ChatMessage
    Me     Person
}

The People data field appears as an empty fragment []. I use a simple find to get 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, you just need to add "bson:" "" at the end of the line People [] Person

+5
source share
1 answer

Figured it out ....

The answer can be found here: https://groups.google.com/d/msg/mgo-users/KirqfCSlKFc/t2l3l4yxFRwJ

Basically, you just need to add "bson:" "" at the end of the line People [] Person

+6
source

All Articles