这些是我的 Mongodb 文档结构。type Company struct {Id bson.ObjectId `bson:"_id,omitempty"`Company_name stringAdmin UserMinimalProcess []ProcessItem}type ProcessItemMinimal struct {Id bson.ObjectId `bson:"_id,omitempty"`Process_name stringProcesstype int64 }type ProcessItem struct{ProcessItemMinimal `bson:",inline"`Sortorder int64 }这是我的 mongodb 文档。{ "_id" : ObjectId("56cd99109096f3b762f4f149"), "company_name" : "xyz", "admin" : { "email" : "kk@kk.kk", "fullname" : "kk" }, "process" : [ { "process_name" : "Enquiry", "processtype" : NumberLong(0), "sortorder" : NumberLong(0) }, { "process_name" : "Converted", "processtype" : NumberLong(1), "sortorder" : NumberLong(1) }, { "process_name" : "MileStone 1", "processtype" : NumberLong(1), "sortorder" : NumberLong(2) } ]}我需要再添加一个“进程”来处理数组。是否可以?如果是,我如何在 mgo 中查询?
1 回答
MMTTMM
TA贡献1869条经验 获得超4个赞
要将另一个文档插入数组,请使用$push
在 mgo 中,
// Create the new 'ProcessItem' document you want to insert.
newProcess := ProcessItem {
ProcessItemMinimal : processItem,
SortOrder : sortOrder
}
change := bson.M {
"$push": bson.M {
"process": newProcess,
},
}
// Update the necessary 'Company' document
companyCollection.UpdateId(company.ID, change)
- 1 回答
- 0 关注
- 177 浏览
添加回答
举报
0/150
提交
取消
