1 回答
TA贡献1936条经验 获得超6个赞
定位使用$elemMatch查找。
参考案例:
exports.updateReply2Async = function (opts) {
var results = {error_code: -1, error_msg: "error"};
var suggestID = helper.toObjectID(opts.doc.suggestID);
var filter = {_id: suggestID,"replies":{ $elemMatch:{rid:opts.doc.rid,replyname:'1100100'}}};
var update = {$set: {"replies.$.replycontent": opts.doc.replynewcontent,"replies.$.reply_at":new Date()}};
return opts.dbs.csdb.collection("suggests").findOneAndUpdateAsync(filter, update, {upsert: false})
.timeout(opts.configs.timeoutnormal)
.then(function (value) {
if (value) {
results.error_code = 0;
results.error_msg = "ok";
results.suggest = value;
} else {
results.error_code = 20002;
results.error_msg = "修改回复数据失败";
}
return results;
});
};
- 1 回答
- 0 关注
- 267 浏览
添加回答
举报