Last active
December 4, 2018 08:48
-
-
Save simonecorsi/471e325e95c379e7520e784a515f1df3 to your computer and use it in GitHub Desktop.
MongoDB shell // Invalidate email in collections
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
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