请问在MongoDB中添加对象数组问题,怎么解决?

在MongoDB中添加对象数组问题,怎么解决


慕勒3428872
浏览 1108回答 1
1回答

qq_遁去的一_1

更新数组字段使用$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})
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MongoDB