我有一个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
}
});如何在Golang中格式化PhoneBook结构,以便可以运行类似这样的查询并将结果解组为一个PhoneBooks数组?
var results []PhoneBook
err = pb.Find(bson.M{}).All(&results)发布于 2014-05-01 07:51:01
我想出来了,这就是对任何可能觉得有用的人的答案。
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
}https://stackoverflow.com/questions/23399318
复制相似问题