我想搜索具有相同action_object.reply.id
或action_target.reply.id
的所有活动。像这样:
Activity
.find({ $or: [
{ 'action_object.reply.id': replyId },
{ 'action_target.reply.id': replyId }
]});
但我也只想像这样更新removed
属性:
Activity
.update({ 'action_object.reply.id': replyId }, {
'action_object.reply.removed': true }, { multi: true });
Activity
.update({ 'action_target.reply.id': replyId }, {
'action_target.reply.removed': true }, { multi: true });
是否有可能以某种方式结合这两个查询?我想更新action_target.reply.removed
action_target.reply.id
或action_object.reply.removed
action_object.reply.id
的位置{/ 1}}。
或者我必须像上面那样写两个不同的查询。
答案 0 :(得分:2)
update
调用的第一个参数是查询对象,因此您可以简单地使用相同的$或查询。 Mongo将更新查询检索的所有文档。
Activity
.update({ $or: [
{ 'action_object.reply.id': replyId },
{ 'action_target.reply.id': replyId }
]}, {'action_object.reply.removed': true }, { multi: true });