title: Nodejs and Mongoose wait till document is saved before callback
body: <p>The following function takes an aggregate cursor containing several arrays of user Ids so the users with the corresponding ids can be modified and then saved. </p>
  
  <p>The issue I am having is getting the function to only return once all the users have been modified and saved. Currently it doesn't do that and when I attempt to access the users later on (literally after this function) the modifications haven't been permeated through. </p>
  
  <p>This is the current code that does the modification (might be some strange async additions as I have been attempting 10s of different options with no success):</p>
  
  <pre><code>function updateUsers(dataArray, done) {
  
  
  dataArray.eachAsync(
   function(data) {
    let userArray = data.users;     
  
    async.forEach(userArray, function(userId, callBack){       
  
      mongoose.model('User').findById(userId, function(err, user) {
        // User document modified         
        user.save(function(err, user){
          callBack();
        });        
      });
    });
  },
  function(err) {
    //Only come here once all the users have been modified and saved!
    if (err) {
      return done(err, false);
    }
  
    return done(err, true);
    } 
   );
  }
  </code></pre>
  
  <p>The data that is passed is: </p>
  
  <blockquote>
    <p>dataArray: Aggregation cursor</p>
  </blockquote>
  
  <p>Result for eachAsync e.g. data is:</p>
  
  <pre><code>{ _id: 'GroupValue',
  users: 
   [ 5a0b2f5bcd0813adeac2435b,
     5a0b2f5bcd0813adeac24357,
     5a0b2f5bcd0813adeac24358 ] }
  </code></pre>