Skip to content

Instantly share code, notes, and snippets.

@cziem
Last active September 21, 2019 12:03
Show Gist options
  • Save cziem/43fefe1e67898187620916725f06a4fd to your computer and use it in GitHub Desktop.
Save cziem/43fefe1e67898187620916725f06a4fd to your computer and use it in GitHub Desktop.
Deletes all inactive users from the DB
const User = require("../../models/user.schema");
const deleteInactives = async () => {
const deletedUsers = await User.deleteMany({ isActive: false });
if (deletedUsers.ok === 1) {
let verb = deletedUsers.n > 1 ? "users" : "user";
console.log(`${deletedUsers.deletedCount} Inactive ${verb} deleted`);
} else {
return "Error deleting users";
}
};
module.exports = deleteInactives;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment