title: Mongo aggregation and MongoError: exception: BufBuilder attempted to grow() to 134217728 bytes, past the 64MB limit
body: <p>I'm trying to aggregate data from my Mongo collection to produce some statistics for FreeCodeCamp by making a large json file of the data to use later.</p>
  
  <p>I'm running into the error in the title. There doesn't seem to be a lot of information about this, and the other posts here on SO don't have an answer. I'm using the latest version of MongoDB and drivers.</p>
  
  <p>I suspect there is probably a better way to run this aggregation, but it runs fine on a subset of my collection. My full collection is ~7GB.</p>
  
  <p>I'm running the script via <code>node aggScript.js &gt; ~/Desktop/output.json</code>
  Here is the relevant code:</p>
  
  <pre><code>MongoClient.connect(secrets.db, function(err, database) {
    if (err) {
      throw err;
    }
  
    database.collection('user').aggregate([
      {
        $match: {
          'completedChallenges': {
            $exists: true
          }
        }
      },
      {
        $match: {
          'completedChallenges': {
            $ne: ''
          }
        }
      },
      {
        $match: {
          'completedChallenges': {
            $ne: null
          }
        }
      },
      {
        $group: {
          '_id': 1, 'completedChallenges': {
            $addToSet: '$completedChallenges'
          }
        }
      }
    ], {
      allowDiskUse: true
    }, function(err, results) {
      if (err) { throw err; }
      var aggData = results.map(function(camper) {
        return _.flatten(camper.completedChallenges.map(function(challenges) {
          return challenges.map(function(challenge) {
            return {
              name: challenge.name,
              completedDate: challenge.completedDate,
              solution: challenge.solution
            };
          });
        }), true);
      });
      console.log(JSON.stringify(aggData));
      process.exit(0);
    });
  });
  </code></pre>