我正在使用 MongoDB 3.4,最近在 Beta 環境中將其升級到 4.4。我有一個使用 facet 的查詢,它給出了超過 100MB 大小限制的問題。我看到 Jira 鏈接在這里解釋了這個問題:https : //jira.mongodb.org/browse/SERVER-40317
查詢是根據用戶輸入動態生成的,因此很難直接對查詢進行更改,我認為這是最后的手段。
我無論如何都在尋找繞過這個限制。AllowDiskUsage 也不能如上述鏈接所述那樣作業。
uj5u.com熱心網友回復:
經確認,這可以解決問題:
db.adminCommand({setParameter: 1, internalQueryFacetMaxOutputDocSizeBytes: 335544320})
使用上述命令影響 RAM 限制從默認 100MB 更改為 320 MB
查看更改是否到位:
use admin
db.runCommand( { getParameter : 1, “internalQueryFacetMaxOutputDocSizeBytes” : 1 } )
此更改是臨時的,要使其永久生效,您需要將其添加到 mongodb.conf 檔案中以在啟動時生效:
setParameter:
internalQueryFacetMaxOutputDocSizeBytes: 335544320
uj5u.com熱心網友回復:
與您的問題不完全相關,但您的聚合管道看起來有點傻。為什么你只用一個引數來使用所有這些$and/ $or?
如果我沒記錯的話,您的聚合管道如下所示:
responses.aggregate([
{
'$match': {
surId: '5f548bda279ef41b7a9cd23c',
preview: 0,
resStatus: '1',
archive: { '$exists': false },
modified: {
'$gte': ISODate('2020-08-31T20:59:59.999Z'),
'$lt': ISODate('2020-11-30T21:00:00.000Z')
},
'resAObj.601aaf29fd93f74cab932141': { $in: [Object] }
}
},
{ $project: { 'resAObj.601aaf29fd93f74cab932141': 1, surId: 1 },
{
'$facet': {
'0': [
{ '$match': { 'resAObj.601aaf29fd93f74cab932141': { '$elemMatch': [Object] } } },
{ '$addFields': { 'resAObj.601aaf29fd93f74cab932141': { '$filter': { input: '$resAObj.601aaf29fd93f74cab932141', as: 'item', cond: { '$and': [Array] } } } } },
{
'$project': {
surId: '$surId',
d_DMID7235_0_d: { '$filter': { input: '$resAObj.601aaf29fd93f74cab932141', as: 'dmi_0', cond: { '$eq': [Array] } } },
d_DMID7237_0_d: { '$filter': { input: '$resAObj.601aaf29fd93f74cab932141', as: 'dmi_0', cond: { '$eq': [Array] } } },
d_DMID7239_0_d: { '$filter': { input: '$resAObj.601aaf29fd93f74cab932141', as: 'dmi_0', cond: { '$eq': [Array] } } },
d_DMID7240_0_d: { '$filter': { input: '$resAObj.601aaf29fd93f74cab932141', as: 'dmi_0', cond: { '$eq': [Array] } } },
d_DMID7241_0_d: { '$filter': { input: '$resAObj.601aaf29fd93f74cab932141', as: 'dmi_0', cond: { '$eq': [Array] } } },
d_DMID7242_0_d: { '$filter': { input: '$resAObj.601aaf29fd93f74cab932141', as: 'dmi_0', cond: { '$eq': [Array] } } },
d_DMID7243_0_d: { '$filter': { input: '$resAObj.601aaf29fd93f74cab932141', as: 'dmi_0', cond: { '$eq': [Array] } } },
d_DMID7244_0_d: { '$filter': { input: '$resAObj.601aaf29fd93f74cab932141', as: 'dmi_0', cond: { '$eq': [Array] } } },
d_DMID7245_0_d: { '$filter': { input: '$resAObj.601aaf29fd93f74cab932141', as: 'dmi_0', cond: { '$eq': [Array] } } },
index: '0'
}
},
{
'$project': {
surId: '$surId',
DMID7235: { '$ifNull': ['$d_DMID7235_0_d', 0] },
DMID7237: { '$ifNull': ['$d_DMID7237_0_d', 0] },
DMID7239: { '$ifNull': ['$d_DMID7239_0_d', 0] },
DMID7240: { '$ifNull': ['$d_DMID7240_0_d', 0] },
DMID7241: { '$ifNull': ['$d_DMID7241_0_d', 0] },
DMID7242: { '$ifNull': ['$d_DMID7242_0_d', 0] },
DMID7243: { '$ifNull': ['$d_DMID7243_0_d', 0] },
DMID7244: { '$ifNull': ['$d_DMID7244_0_d', 0] },
DMID7245: { '$ifNull': ['$d_DMID7245_0_d', 0] },
index: '0'
}
}
],
'1': ['... same as above'],
'2': ['... same as above'],
'3': ['... same as above'],
'4': ['... same as above'],
'5': ['... same as above'],
'6': ['... same as above'],
'7': ['... same as above'],
total: [{ '$count': 'total' }],
baseValue: ['... same as above']
}
},
{ '$project': { mergedArray: { '$concatArrays': ['$0', '$1', '$2', '$3', '$4', '$5', '$6', '$7', '$total', '$baseValue'] } } },
{ '$unwind': '$mergedArray' },
{ '$replaceRoot': { newRoot: '$mergedArray' } }
])
你所有的操作都基于一個欄位resAObj.601aaf29fd93f74cab932141,這看起來很奇怪。也許純 javascript 代碼可以更好地解決它。
您可以使用$map、$arrayToObject和$ objectToArray。實際上,我根本看不出使用的理由$facet。
如果沒有樣本輸入資料和樣本結果,很難給出答案,但我認為聚合管道可以寫得更簡單。
uj5u.com熱心網友回復:
你必須像這樣使用 mongoose utils allowdiskusage:
return OrderEntity
.aggregate(compendiumAggregation(query))
.allowDiskUse(true)
.then(success(res))
.catch(next);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/390978.html
下一篇:如何在反應中更改分頁變數
