Mongo异步呼叫

I have this Ajax route:

router.get('/getThey', middleware.isLoggedIn, function(req, res){
var array = [];
var followingLength = req.user.they.length -1;


req.user.they.forEach(function(userId, i){
  User.findById(userId, function(err, foundUser){
    foundUser.theySent.forEach(function(theySent, i){
      var foundLength = foundUser.theySent.length -1;

      while(i !== foundLength){
        if(req.user.notifications.indexOf(theySent) === -1){
          req.user.notifications.push(theySent);
          req.user.save();
        }
      }
    });
  });
 }); 

 res.json(req.user.notifications);
 });

But the code below runs first because the User findById

if(aux === true && i === followingLength){
  res.json(req.user.notifications);
}

What can I do to make findById Synchronous ?

findById is specifically designed to take a callback or promise. Since it is making an async call, it will not be sync so you would have to restructure code accordingly.