'join' MongodDB collections with a for loop
The nested loops perform books.length * favorites.length iterations (up to 4 million).

Instead build a dictionary of id -> rating, so total iterations max is a sum of lengths.

var favRatings = {}, i, len;

for (i = 0, len = favorites.length; i &lt; len; i++) {
    var fav = favorites[i];
    favRatings[fav.bookId] = fav.myRating;
}

for (i = 0, len = books.length; i &lt; len; i++) {
    var book = books[i];
    var rating = favRatings[book._id];
    if (rating !== undefined) {
        book.userRating = rating;  
    }
}