Skip to content

Instantly share code, notes, and snippets.

@simonecorsi
Last active December 4, 2018 08:48
Show Gist options
  • Save simonecorsi/471e325e95c379e7520e784a515f1df3 to your computer and use it in GitHub Desktop.
Save simonecorsi/471e325e95c379e7520e784a515f1df3 to your computer and use it in GitHub Desktop.
MongoDB shell // Invalidate email in collections
db.getCollectionNames().map(function(collection) {
var hasEmailField = db[collection].count({ email: { $exists: true }})
if ( !hasEmailField ) return "no email field in : " + collection
db[collection].find({}).map(function(item) {
db[collection].update(
{ _id: item._id },
{
$set: {
email: item.email.replace(
/@.*\..*/,
'@INVALID_' + Date.now() + '_INVALID.fake'
)
}
}
);
});
return "cleared email from: " + collection
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment