title: MongoError Total size of documents exceeds maximum document size
body: <p>I am having issues with $aggregate with mongoose. I am using $lookup to get the document from the raps table, but as the size of the raps documents with matching userId is huge it fails every time.</p>
  
  <p>errmsg: 'Total size of documents in raps matching { $match: { $and: [ { owner._id: { $eq: "ID" } }, {} ] } }
   exceeds maximum document size',
    code: 4568</p>
  
  <p>I have tried with allowDiskUse and it didn't work also tried $out and adding it into temp table, didn't work either. </p>
  
  <p>I have also tried using $unwind after the $lookup as mentioned in one of the answer, but it doesn't seem to work.</p>
  
  <p>I have the following snippet.</p>
  
  <pre><code>userAccountModel.aggregate([
    {
      $match:
        {
          _id: userId
        }
    },
    {
      $lookup: {
        from: "raps",
        localField: "_id",
        foreignField: "owner._id",
        as: "rapsDocs"
      }
    },
    {
      $project : {
        "likes": { $sum: "$rapsDocs.likes" }
      }
    }
  ]).allowDiskUse(true).exec(function(err, result){
  })
  </code></pre>