如何对mongodb两个集合和集合内嵌套数组对象进行update更改
展开全部
更新数组字段使用$push关键词提供参考代码:使用node.jsvar filter;if (paramtype === 1) { filter = {helpapiuuid: helpapiuuid, "requests.paramid": opts.paramid};} else { filter = {helpapiuuid: helpapiuuid, "responses.paramid": opts.paramid};}var update;if (paramtype === 1) { update = { $set: { "requests.$.param": opts.param, "requests.$.type": opts.desc, "requests.$.desc": opts.desc, "requests.$.default": opts.default } };} else { update = { $set: { "responses.$.param": opts.param, "responses.$.type": opts.desc, "responses.$.desc": opts.desc, "responses.$.default": opts.default } };}return publicdb.collection(colname).findOneAndUpdateAsync(filter, update, {upsert: false})
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询