On this page本页内容
New in version 4.4.在版本4.4中新增。
cursor.allowDiskUse()
This is a 这是mongosh
method. mongosh
方法。This is not the documentation for 这不是Node.js或其他特定于编程语言的驱动程序方法的文档。Node.js
or other programming language specific driver methods.
In most cases, mongosh
methods work the same way as the legacy mongo
shell methods. However, some legacy methods are unavailable in mongosh
.
For the legacy mongo
shell documentation, refer to the documentation for the corresponding MongoDB Server release:
For MongoDB API drivers, refer to the language specific MongoDB driver documentation.
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:具有以下形式:
db.collection.find(<match>).sort(<sort>).allowDiskUse()
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兆字节的内存)应答的排序操作没有影响。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:集合包含类似于以下内容的文档:
{ "sensor-name" : "TEMP-21425", "sensor-location" : "Unit 12", "reading" : { "timestamp" : Timestamp(1580247215, 1), "value" : 212, "unit" : "Farenheit" } }
The following operation includes a 以下操作在读取时间戳的字段上包含cursor.sort()
on the field reading.timestamp
. cursor.sort()
。The operation also includes 该操作还包括cursor.allowDiskUse()
to support the sort operation.cursor.allowDiskUse()
以支持排序操作。
db.sensors.find({"sensor-location" : "Unit 12"}). sort({"reading.timestamp" : 1}). 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将返回错误。