On this page本页内容
New in version 4.4.版本4.4中的新功能。
cursor.
allowDiskUse
()¶mongo
Shell Method
This page documents the 本页记录了mongo
shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. mongo
shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。
allowDiskUse()
allows MongoDB to use temporary files on disk to store data exceeding the 100 megabyte system memory limit while processing a blocking sort operation. 允许MongoDB在处理阻塞排序操作时,使用磁盘上的临时文件存储超过100 MB系统内存限制的数据。If MongoDB requires using more than 100 megabytes of system memory for the blocking sort operation, MongoDB returns an error unless the query specifies 如果MongoDB需要使用超过100 MB的系统内存来执行阻塞排序操作,MongoDB将返回错误,除非查询指定cursor.allowDiskUse()
.cursor.allowDiskUse()
。
allowDiskUse()
has the following form:具有以下形式:
See Sort and Index Use for more information on blocking sort operations.有关阻止排序操作的更多信息,请参阅排序和索引使用。
cursor.allowDiskUse()
has no effect on sort operations answered using an index or non-indexed (“blocking”) sort operations which require less than 100 megabytes of memory. 对使用索引或非索引(“阻塞”)排序操作(所需内存小于100 MB)回答的排序操作没有影响。For more complete documentation on blocking sorts and sort index use, see Sort and Index Use.有关阻止排序和排序索引使用的更完整文档,请参阅排序和索引使用。
To check if MongoDB must perform an blocking sort, append 要检查MongoDB是否必须执行阻塞排序,请将cursor.explain()
to the query and check the explain results. cursor.explain()
附加到查询并检查解释结果。If the query plan contains a 如果查询计划包含SORT
stage, then MongoDB must perform an blocking sort operation subject to the 100 megabyte memory limit.SORT
阶段,则MongoDB必须在100 MB内存限制下执行阻塞排序操作。
Consider a collection 考虑一个只有在默认sensors
with only the default index on _id
. _id
上的集合sensors
。The collection contains documents similar to the following:该集合包含与以下内容类似的文档:
The following operation includes a 以下操作包括cursor.sort()
on the field reading.timestamp
. reading.timestamp
字段上的cursor.sort()
。The operation also includes 该操作还包括支持排序操作的cursor.allowDiskUse()
to support the sort operation.cursor.allowDiskUse()
。
Since 由于reading.timestamp
is not included in an index, MongoDB must perform a blocking sort operation to return results in the requested sort order. reading.timestamp
不包含在索引中,MongoDB必须执行阻塞排序操作,以按请求的排序顺序返回结果。By specifying 通过指定allowDiskUse()
, MongoDB can process the sort operation even if it requires more than 100 megabytes of system memory. allowDiskUse()
,MongoDB可以处理排序操作,即使它需要超过100 MB的系统内存。If 如果省略allowDiskUse()
was omitted and the operation required more than 100 megabytes of system memory, MongoDB would return an error.allowDiskUse()
,并且该操作需要超过100 MB的系统内存,MongoDB将返回一个错误。