Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using golang's mgo library, how do you retrieve nested objects such as lists

Tags:

go

mgo

I am trying to retrieve an object that fills this class:

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

The data field "People" comes up as an empty slice []. I am using a simple find to get the 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, just need to add 'bson: ""' at the end of the People []Person line

like image 412
user1744376 Avatar asked Jan 29 '13 18:01

user1744376


1 Answers

Figured it out....

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

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

like image 171
user1744376 Avatar answered Sep 22 '22 04:09

user1744376