次のようなMongoスキーマがあります。
var phoneBookSchema = Schema({
user_id: {
type: Schema.Types.ObjectId,
ref: 'User',
index: {
unique : true
},
required: true
},
entries: {
type: [entry],
default: []
},
matches: {
type: [],
default: []
}
});
エントリ ドキュメントの配列は次のようになります。
var entry = Schema({
_id : false,
phone: {
type: String,
index: true
},
name: {
type: String
},
notified: {
type: Boolean,
default: false,
required: true
}
});
このようなクエリを実行し、結果を PhoneBook の配列にアンマーシャリングできるように、Golang で PhoneBook 構造体をフォーマットするにはどうすればよいですか?
var results []PhoneBook
err = pb.Find(bson.M{}).All(&results)