Aggregation Pipeline Limits聚合管道限制

On this page本页内容

Aggregation operations with the aggregate command have the following limitations.使用aggregate命令的聚合操作具有以下限制。

Result Size Restrictions结果大小限制

Changed in version 3.6:在版本3.6中更改:MongoDB 3.6 removes the option for the aggregate command to return its results as a single document.MongoDB 3.6删除了aggregate命令将结果作为单个文档返回的选项。

The aggregate command can return either a cursor or store the results in a collection.aggregate命令可以返回游标,也可以将结果存储在集合中。When returning a cursor or storing the results in a collection, each document in the result set is subject to the BSON Document Size limit, currently 16 megabytes; if any single document that exceeds the BSON Document Size limit, the command will produce an error.返回游标或将结果存储在集合中时,结果集中的每个文档都受BSON文档大小限制(当前为16兆字节)的约束;如果任何单个文档超过BSON文档大小限制,则该命令将产生错误。 The limit only applies to the returned documents; during the pipeline processing, the documents may exceed this size.此限制仅适用于返回的文档;在流水线处理过程中,文档可能超过此大小。The db.collection.aggregate() method returns a cursor by default.db.collection.aggregate()方法默认返回一个游标。

Memory Restrictions内存限制

Pipeline stages have a limit of 100 megabytes of RAM.管道级的RAM限制为100兆字节。If a stage exceeds this limit, MongoDB will produce an error.如果某个阶段超过此限制,MongoDB将产生一个错误。To allow for the handling of large datasets, use the allowDiskUse option to enable aggregation pipeline stages to write data to temporary files.要允许处理大型数据集,请使用allowDiskUse选项启用聚合管道阶段以将数据写入临时文件。

Changed in version 3.4.在版本3.4中更改。

The $graphLookup stage must stay within the 100 megabyte memory limit.$graphLookup阶段必须保持在100MB内存限制内。If allowDiskUse: true is specified for the aggregate() operation, the $graphLookup stage ignores the option.如果为aggregate()操作指定allowDiskUse:true$graphLookup阶段将忽略该选项。If there are other stages in the aggregate() operation, allowDiskUse: true option is in effect for these other stages.如果aggregate()操作中还有其他阶段,则allowDiskUse: true选项对这些其他阶段有效。

Starting in MongoDB 4.2, the profiler log messages and diagnostic log messages includes a usedDisk indicator if any aggregation stage wrote data to temporary files due to memory restrictions.从MongoDB 4.2开始,如果任何聚合阶段由于内存限制将数据写入临时文件,那么profiler日志消息诊断日志消息将包含usedDisk指示符。