UpdateOptions语法更新mongodb数组中符合条件的对象
1.定义条件(elem可自定义)
interfaceArr:=make([]interface{},0)
interfaceArr=append(interfaceArr,bson.m{
"elem.id":"111",
})
_,err:=dao.userDao.UpdateAll(ctx,bson.m{},bson.m{
"$set":bson.m{
"items.$[].opt.$[elem].desc":"测试",
},
},
options.UpdateOptions{
UpdateOptions:$opt.UpdateOption{
ArrayFilters:$opt.ArrayFilters{
Filters:interfaceArr,
},
},
})
2.数据结构
标签:opt,mongodb,elem,interfaceArr,go,bson,UpdateOptions From: https://www.cnblogs.com/liuyuanchen/p/17021589.html