1 回答
TA贡献1824条经验 获得超8个赞
func (o *MongoOps) AddToBsonMapElement(lstMap map[string]interface{}, Operation string, key string, value interface{}) (result map[string]interface{}) {
status, msg := EmptyStructCheck(o)
if status == true {
LogError(msg)
panic(msg)
}
if Operation == "$addToSetEach" {
if _, ok := lstMap["$addToSet"]; ok {
childmap := lstMap["$addToSet"]
subchildmap := childmap.(map[string]interface{})
var val map[string]interface{}
val = make(map[string]interface{})
val["$each"] = value
subchildmap[key] = val
lstMap["$addToSet"] = subchildmap
} else {
lstMap["$addToSet"] = bson.M{key: bson.M{"$each": value}}
}
fmt.Println(reflect.TypeOf(lstMap))
} else if _, ok := lstMap[Operation]; ok {
childmap := lstMap[Operation]
subchildmap := childmap.(map[string]interface{})
subchildmap[key] = value
lstMap[Operation] = subchildmap
} else {
childmap := make(map[string]interface{}, 0)
childmap[key] = value
lstMap[Operation] = childmap
}
return lstMap
}
这是你可以尝试的
- 1 回答
- 0 关注
- 366 浏览
添加回答
举报