javascript - 如何解决 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
谁能帮我这个?请告诉我如何解决这个问题。提前致谢。
解决方案
您$lookup
可能匹配的记录太多。您可以$lookup
使用$unwind
. 根据官方文档,
当 $unwind 紧跟在另一个 $lookup 之后,并且 $unwind 在 $lookup 的 as 字段上运行时,优化器可以将 $unwind 合并到 $lookup 阶段。这避免了创建大型中间文档。
推荐阅读
- c# - C# 如何将序列化的 .NET 对象编译为 .NET 程序集
- c# - 可以使 IntelliSense 不区分重音吗?
- java - 通过捆绑在片段之间传递值
- webview - 在电子的另一个webview中打开一个webview的devtools?
- c# - 从 C# 中的类更新 GUI 的正确方法
- java - 使用 xml 配置休息 Spring bean
- ios - 在另一个文件的函数主视图中显示警报
- spring - Spring application.properties 中的 Integer.MAX_VALUE
- android - 自 API 26 起不推荐使用 Build.SERIAL:Android 8.0 Oreo
- vba - 在 VBA Excel 中设置工作簿语言