猫鼬:如何更新所有符合条件的人?

编程入门 行业动态 更新时间:2024-10-27 15:28:27
本文介绍了猫鼬:如何更新所有符合条件的人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经做过这样的事情(请原谅我对示例的愚蠢...:-):

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) { });

更多推荐

猫鼬:如何更新所有符合条件的人?

本文发布于:2023-10-16 15:51:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1498028.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:的人   符合条件   猫鼬

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!