Last active
August 29, 2015 14:13
-
-
Save freeCodeCamp/c62e3455402259a9389d to your computer and use it in GitHub Desktop.
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
User.find({'profile.picture': /twimg.*_normal/}, function (err, users) { | |
if (err) { debug('Username err: ', err); return next(err); } | |
for (var i = 0; i < users.length; i++) { | |
user = users[i]; | |
if (user.profile.picture) { | |
user.profile.picture = user.profile.picture.replace('_normal', ''); | |
user.save(function(err) { | |
if (err) { return next(err); } | |
console.log(user.profile.picture); | |
done(err, user); | |
}); | |
} | |
} | |
process.exit(0); | |
}); |
and the process.exit is being called before any of the save methods can complete. It should be added as the last task in an async series
https://github.com/caolan/async#each each(arr, iterator, callback) where arr is the users array, iterator is where you call the save method, can callback is where you call process.exit(0)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see. You should use the async module and async.each(arr, function() {//doo stuff})