所以最近我一直试图使用mgo将不同类型的数据插入到结构中,我遇到了一些障碍。当试图插入一个对象ID数组时,如果我要在结构中填充该对象ID数组,我似乎无法弄清楚该格式。
以下结构如下
type Group struct {
ID bson.ObjectId `json:"id" bson:"_id"`
GroupName string `json:"groupName"`
UserIDs []*bson.ObjectId `json:"users" bson:"userid"`
Expected []*int `json:"expected"`
Actual []*int `json:"actual"`
}
我尝试运行的操作是将一个带有单个userID的新“测试”表插入到UserID中。
array := []*bson.ObjectId{&findJ.ID}
c = Session.DB("test").C("Group")
err = c.Insert(&Group{GroupName: "test", UserIDs: array})
ThisPanic(err)
findJ在单独的结构中拥有自己的ID。我在这里做错了什么,因为它引起了插入数组的恐慌。