Skip to content

Instantly share code, notes, and snippets.

@freeCodeCamp
Last active August 29, 2015 14:13
Show Gist options
  • Save freeCodeCamp/c62e3455402259a9389d to your computer and use it in GitHub Desktop.
Save freeCodeCamp/c62e3455402259a9389d to your computer and use it in GitHub Desktop.
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);
});
@BerkeleyTrue
Copy link

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

@BerkeleyTrue
Copy link

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