Docs Menu

cursor.allowDiskUse()

cursor.allowDiskUse()

重要

mongosh メソッド

このページでは、mongosh メソッドについて記載しています。これは Node.js などの言語固有のドライバーのドキュメントではありません

MongoDB API ドライバーについては、各言語の MongoDB ドライバー ドキュメントを参照してください。

使用 allowDiskUse() to either allow or prohibit writing temporary files on disk when a pipeline stage exceeds the 100 megabyte limit. Starting in MongoDB 6.0, operations that require greater than 100 megabytes of memory automatically write data to temporary files by default.

allowDiskUse()の形式は次のとおりです。

db.collection.find(<match>).sort(<sort>).allowDiskUse()

ブロッキングソート操作の詳細については、「ソートとインデックスの使用」を参照してください。

このメソッドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです

注意

このコマンドは、すべての MongoDB Atlas クラスターでサポートされています。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

Starting in MongoDB 6.0, pipeline stages that require more than 100 megabytes of memory to execute write temporary files to disk by default.

注意

Prior to MongoDB 6.0, .allowDiskUse(false) and .allowDiskUse(true) have the same effect. In MongoDB 6.0, both mongosh and the legacy mongo shell behave the following way:

If allowDiskUseByDefault is true (this is the default):

  • .allowDiskUse() has no additional effect

  • .allowDiskUse(true) has no additional effect

  • .allowDiskUse(false) prohibits the query from writing temporary files to disk

If allowDiskUseByDefault is false:

  • .allowDiskUse() enables writing temporary files to disk

  • .allowDiskUse(true) enables writing temporary files to disk

  • .allowDiskUse(false) has no additional effect

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. For more complete documentation on blocking sorts and sort index use, see ソートとインデックスの使用.

To check if MongoDB must perform an blocking sort, append cursor.explain() to the query and check the explain results. If the query plan contains a SORT stage, then MongoDB must perform an blocking sort operation subject to the 100 megabyte memory limit.

Consider a collection sensors with only the default index on _id. The collection contains documents similar to the following:

{
"sensor-name" : "TEMP-21425",
"sensor-location" : "Unit 12",
"reading" : {
"timestamp" : Timestamp(1580247215, 1),
"value" : 212,
"unit" : "Fahrenheit"
}
}

The following operation includes a cursor.sort() on the field reading.timestamp. The operation also includes cursor.allowDiskUse() to support the sort operation.

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. By specifying allowDiskUse(), MongoDB can process the sort operation even if it requires more than 100 megabytes of system memory. If allowDiskUse() was omitted and the operation required more than 100 megabytes of system memory, MongoDB would return an error.