Question
Update many in mongoose
I have a very simple case. I want to update my collection every midnight.
Im using node-schedule
:
schedule.scheduleJob('0 0 * * *', () => {
Users.updateMany();
});
All I want to do, is to loop over every document in my collection (Users
) and then if User.created
is false
, I want to turn it into true
.
In javascript it would be:
for (let user in Users) {
if (user.created === false) {
user.created = true;
}
}
How to do it in mongoose? Thanks!