I have this chunk of code
User.find({}, function(err, users) { for (var i = 0; i < users.length; i++) { pseudocode Friend.find({
You can also take a look at the Async JavaScript library: Async It provides utility functions for ordering the execution of asynchronous functions in JavaScript.