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); | |
}); |
I've updated to check for existence. Note that this is a standalone script we're hoping to run on the database, thus the need for an exit.
your also calling multiple an async function multiple times with a callback that ends with done. The first time done is called ends the function
I see. You should use the async module and async.each(arr, function() {//doo stuff})
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
https://gist.github.com/FreeCodeCamp/c62e3455402259a9389d#file-gistfile1-txt-L3 should say
return next(err);
line 5 should check for existance first before calling a string method. i.e. thing.string = thing.string || '';
process.exit(0) here seems out of place. Are you sure you want that there?