Last active
September 21, 2019 12:03
-
-
Save cziem/43fefe1e67898187620916725f06a4fd to your computer and use it in GitHub Desktop.
Deletes all inactive users from the DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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