On this page本页内容
Aggregation operations with the 使用aggregate command have the following limitations.aggregate命令的聚合操作具有以下限制。
The aggregate command can either return a cursor or store the results in a collection. aggregate命令可以返回游标,也可以将结果存储在集合中。Each document in the result set is subject to the 16 megabyte BSON Document Size limit. 结果集中的每个文档都受16兆字节BSON文档大小限制的约束。If any single document exceeds the BSON Document Size limit, the aggregation produces an error. 如果任何单个文档超过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()方法返回一个游标。
Changed in version 5.0.在版本5.0中更改。
Each individual pipeline stage has a limit of 100 megabytes of RAM. 每个单独的流水线级的RAM限制为100兆字节。By default, if a stage exceeds this limit, MongoDB produces an error. 默认情况下,如果某个阶段超过此限制,MongoDB将生成错误。For some pipeline stages you can allow pipeline processing to take up more space by using the allowDiskUse option to enable aggregation pipeline stages to write data to temporary files.对于某些管道阶段,可以使用allowDiskUse选项允许聚合管道阶段将数据写入临时文件,从而允许管道处理占用更多空间。
The $search aggregation stage is not restricted to 100 megabytes of RAM because it runs in a separate process.$search聚合阶段不限于100兆字节的RAM,因为它在单独的进程中运行。
Examples of stages that can spill to disk when allowDiskUse is true are:allowDiskUse为true时可能溢出到磁盘的阶段示例如下:
$bucket$bucketAuto$group$sort$sortByCountPipeline stages operate on streams of documents with each pipeline stage taking in documents, processing them, and then outputing the resulting documents.管道阶段对文档流进行操作,每个管道阶段接收文档,处理它们,然后输出结果文档。
Some stages can't output any documents until they have processed all incoming documents. 某些阶段在处理所有传入文档之前无法输出任何文档。These pipeline stages must keep their stage output in RAM until all incoming documents are processed. 这些管道阶段必须将其阶段输出保存在RAM中,直到处理所有传入文档。As a result, these pipeline stages may require more space than the 100 MB limit.因此,这些流水线阶段可能需要比100 MB限制更多的空间。
If the results of one of your 如果某个$sort pipeline stages exceed the limit, consider adding a $limit stage.$sort管道阶段的结果超过限制,请考虑添加$limit阶段。
Starting in MongoDB 4.2, the profiler log messages and diagnostic log messages includes a 从MongoDB 4.2开始,如果任何聚合阶段由于内存限制而将数据写入临时文件,则探查器日志消息和诊断日志消息将包含一个usedDisk indicator if any aggregation stage wrote data to temporary files due to memory restrictions.usedDisk指示符。