AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

cursor.isExhausted()(mongoshメソッド)

cursor.isExhausted()

重要

mongosh メソッド

This page documents a mongosh method. This is not the documentation for a language-specific driver, such as Node.js.

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

次の値を返します。

ブール値

cursor.isExhausted() returns false if documents remain in the current document batch read by the cursor. Otherwise, returns true.

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

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

注意

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

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

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

追尾可能 ( tailable) カーソルでは、 isExhausted()を使用できます。 現在のバッチにドキュメントが残っていない場合でも、追尾可能 (tailable) カーソルは開いたままになります。 ドキュメントがなくなると、他のカーソルは自動的に閉じられます。

変更ストリームではisExhausted()は使用できません。 代わりに、次の有無を確認します。

変更ストリームの例については、「監視の例」と「変更ストリーム イメージの例 」を参照してください。

このセクションには、カーソルを使用して、気象センサーからの温度読み取り値を持つドキュメントを読み取る例が含まれています。 You'll see examples of isExhausted().

1

実行:

db.sensor.insertMany( [
{ _id: 0, temperature: 12 },
{ _id: 1, temperature: 23 }
] )
2

sensorコレクションからドキュメントを読み取るsensorCursorという名前のカーソル変数を作成します。

var sensorCursor = db.sensor.find()
3

実行:

sensorCursor.count()

コレクションに 2 つのドキュメントがあるため、出力は2です。

4

実行:

sensorCursor.next()

出力:

{ _id: 0, temperature: 12 }
5

実行:

sensorCursor.isExhausted()

sensorCursorに残りのドキュメントがあるため、出力はfalseです。

6

実行:

sensorCursor.next()

出力:

{ _id: 1, temperature: 23 }
7

実行:

sensorCursor.next()

追加のドキュメントはなく、この例ではnullが返されます。

8

実行:

sensorCursor.isExhausted()

ドキュメントはなくなり、 isExhausted()はtrueを返します。

このページを評価

項目一覧