0

I want to populate other collection by using lookup query but it gives me this error:-

Total size of documents in images-extractions matching pipeline's $lookup stage exceeds 16793600 bytes

My database models look like this:- Images-Extractions Model

{
   "_id":ObjectId("610109cce690258166ed9ee1"),
   "fileRef":ObjectId("610108e26532080a11417225"), 
   "imageName":"image 1",
   "imageSize":664156,
   // other fields
}

File Model:-

{
   "_id":ObjectId("610108e26532080a11417225"),
   "fileStatus":"ACTIVE",
   // other fields
}

I have used this query on file model in aggregation :-

[
  {
    '$match': {
      '_id': ObjectId('610108e26532080a11417225')
    }
  }, 
  {
    '$lookup': {
      'from': 'images-extractions', 
      'as': 'imagesExtractions', 
      'localField': '_id', 
      'foreignField': 'fileRef'
    }
  }
]

And this query gives me the following error:- Total size of documents in images-extractions matching pipeline's $lookup stage exceeds 16793600 bytes

Can anyone help me with this? Please tell me how to fix this. Thanks in advance.

Dev
  • 57
  • 9
  • Check this out https://stackoverflow.com/questions/45724785/aggregate-lookup-total-size-of-documents-in-matching-pipeline-exceeds-maximum-d – Arthur Costa Jul 30 '21 at 03:05

1 Answers1

0

Your $lookup probably matched too many records. You can follow up your $lookup with an $unwind. According to official documentation,

When a $unwind immediately follows another $lookup, and the $unwind operates on the as field of the $lookup, the optimizer can coalesce the $unwind into the $lookup stage. This avoids creating large intermediate documents.

ray
  • 11,310
  • 7
  • 18
  • 42