首页 > 解决方案 > 如何解决 MongoDB 中的最大大小问题?

问题描述

我想通过使用查找查询来填充其他集合,但它给了我这个错误:-

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

我的数据库模型如下所示:- 图像提取模型

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

文件模型:-

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

我在聚合中的文件模型上使用了这个查询:-

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

这个查询给了我以下错误: -Total size of documents in images-extractions matching pipeline's $lookup stage exceeds 16793600 bytes

谁能帮我这个?请告诉我如何解决这个问题。提前致谢。

标签: javascriptnode.jsmongodbmongooseaggregation-framework

解决方案


$lookup可能匹配的记录太多。您可以$lookup使用$unwind. 根据官方文档

当 $unwind 紧跟在另一个 $lookup 之后,并且 $unwind 在 $lookup 的 as 字段上运行时,优化器可以将 $unwind 合并到 $lookup 阶段。这避免了创建大型中间文档。


推荐阅读