我已经做过这样的事情(请原谅我对示例的愚蠢...:-):
I have do do something like this (please forgive me about the stupidity of the example... :-):
var dateRef = new Date(1990, 1, 1); Person .where('dateOfBirth').gte(dateRef) .update({ $set: { isYoung: true } }, function (err, count) { }) ;即:对于每个出生日期(dateOfBirth)晚于参考日期的Person文档,我想将其设置为true字段isYoung.
I.e.: I'd like to $set to true field isYoung for every Person document whose date of birth (dateOfBirth) is later than a reference date.
即使(当前)有很多文档符合条件(所有年轻人,这里... :-),我的代码也只适用于一个人.
My code is working for just one person, even if (currently) many documents do match the condition (all young people, here... :-).
有任何线索吗?
P.S .:作为奖励,如果可能的话,我也想将不匹配的人isYoung字段设置为false ...
P.S.: as a bonus, I'd like to set not-matching persons isYoung field to false, too, if possible...
推荐答案您应该在更新中使用multi:true来更新多个文档,例如:
You should use multi:true in update to update multiple documents like :
var dateRef = new Date(1990, 1, 1); Person .where('dateOfBirth').gte(dateRef) .update({ $set: { isYoung: true } },{multi: true}, function (err, count) { });更多推荐
猫鼬:如何更新所有符合条件的人?
发布评论