Last active
August 29, 2015 14:13
-
-
Save freeCodeCamp/a6441077db4c08560c1a to your computer and use it in GitHub Desktop.
Sample Mongo migrations
This file contains 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.users.find({'profile.picture': /twimg.*_normal/}).forEach( function(user) { | |
var picture = user.profile.picture.replace(/_normal/, ''); | |
user.profile.picture = picture; | |
db.users.save( user ); | |
print(user.profile); | |
}); | |
db.users.find({email: /@twitter.com/}).forEach( function(user) { | |
var username = user.email.replace('@twitter.com', ''); | |
user.profile.username = username; | |
user.profile.twitterHandle = username; | |
user.email = undefined; | |
db.users.save( user ); | |
print(user.profile.username, user.email); | |
}); | |
db.users.find({'profile.username': {$exists: false}}).forEach( function(user) { | |
var username = "fccuser" + index++ + Math.floor((Math.random() * userCount)); | |
user.profile.username = username; | |
db.users.save( user ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment