I have a Mongo schema that looks like this:
var phoneBookSchema = Schema({
user_id: {
type: Schema.Types.ObjectId,
ref: 'User',
index: {
unique : true
},
required: true
},
entries: {
type: [entry],
default: []
},
matches: {
type: [],
default: []
}
});
The array of entry documents looks like this:
var entry = Schema({
_id : false,
phone: {
type: String,
index: true
},
name: {
type: String
},
notified: {
type: Boolean,
default: false,
required: true
}
});
How do I format the PhoneBook struct in Golang so that I can run a query like this and unmarshall the results into an array of PhoneBooks?
var results []PhoneBook
err = pb.Find(bson.M{}).All(&results)
I figured it out, here is the answer for anyone who might find it useful.
type PhoneBook struct {
User_id bson.ObjectId
Entries []Entry
Matches []User
}
type Entry struct {
Phone string
Name string
Notified bool
}
type User struct {
User_id string
Username string
}