dongxiongshi9952 2015-11-24 18:36
浏览 61

在mgo中插入对象ID的数组

So recently I've been trying to insert different types of data into structures using mgo, and I've ran into a bit of a snag. When trying to insert an array of object IDs, I can't seem to figure out that format if I were to populate that object ID array within the structure.

Here's the structure as follows

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"`
}

And the operation I am trying to run is to insert a new "test" table with a single userID into UserIDs.

array := []*bson.ObjectId{&findJ.ID}

c = Session.DB("test").C("Group")
err = c.Insert(&Group{GroupName: "test", UserIDs: array})
ThisPanic(err) 

Where findJ has it's own ID from a separate structure. What am I doing wrong here, as it is causing a panic on inserting the array.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 链接问题 C++LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型
    • ¥15 求学软件的前人们指明方向🥺
    • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接