0

Given the following code:

Classes.aggregate([
      {
        $lookup: {
          from: "files",
          localField: "classId",
          foreignField: "_id",
          as: "cl"
        }
      }, {
        $unwind: "$files"
      },
      {
        $project: {
          "_id": 1,
          "files.file": 1
        }
      },
      {
        "$group": {
          "_id": "$_id"
        }
      }
    ]).exec...

I am getting the following error:

Total size of documents in files matching { $match: { $and: [ { _id.str: { $eq: null } }, {} ] } } exceeds maximum document size

I have read other articles on StackOverflow but cant seem to resolve.

I have a collection of classes with _id field in mongodb (ObjectId)

The join statement is trying to join files collection on classId (string)

Please note that the files stable contains a field called buffer which contains base64 data. (large field size)

Thanks in advance, Judson

Judson Terrell
  • 4,204
  • 2
  • 29
  • 45
  • it seems the you base64 data field exceeds 16mb (total size of a document in mongodb) – Elmer Dantas Aug 20 '17 at 15:14
  • But I need these fields. What can I do then? – Judson Terrell Aug 20 '17 at 17:17
  • Your `$unwind` is incorrect. As explained in the [linked duplicate](https://stackoverflow.com/questions/45724785/aggregate-lookup-total-size-of-documents-in-matching-pipeline-exceeds-maximum-d/45726501#45726501) adding `$unwind` is the correct thing to do here, however you specified the incorrect field path. It should be `{ "$unwind": "$cl" }` which is what would have been the output "array" specified with `"as": "cl"`, and the applied `unwinding` action actually makes these separate documents instead of an array. Using the incorrect path negates the required alteration. – Neil Lunn Aug 20 '17 at 23:57
  • Neil, I actually made a typeo there. After fixing I was still getting error. I read that other stack overflow article tried that stuff but it didn't work I was getting back an empty array :-( if I could lead you to post a correct answer I will gladly accept help is greatly appreciated. Let me know if you need any more details. People have different ways of learning and I am for one very visual so seeing code for this particular circumstance would help greatly – Judson Terrell Aug 21 '17 at 00:19

0 Answers0