Skip to content

Commit 71dff01

Browse files
committed
updateMany instead of one by one
1 parent d82a0ed commit 71dff01

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

bin/scripts/member-managament/disable_2fa.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,11 @@ pluginManager.dbConnection().then(async(countlyDb) => {
2424
console.log(`The following ${users.length} user(s) 2FA will be disabled: `);
2525
console.log(JSON.stringify(users));
2626
if (!dry_run) {
27-
await Promise.all(users.map(async(user) => {
28-
let userId = user._id;
29-
await countlyDb.collection("members").findAndModify(
30-
{_id: userId},
31-
{},
32-
{
33-
$set: {"two_factor_auth.enabled": false},
34-
$unset: {"two_factor_auth.secret_token": ""}
35-
}
36-
);
37-
console.log("2FA removed: ", JSON.stringify(user));
38-
}));
27+
await countlyDb.collection('members').updateMany({_id: {$in: users.map(user=>user._id)}},
28+
{
29+
$set: {"two_factor_auth.enabled": false},
30+
$unset: {"two_factor_auth.secret_token": ""}
31+
});
3932
console.log("All done");
4033
}
4134
}

0 commit comments

Comments
 (0)