cursor.isExhausted()重要
mongosh メソッド
This page documents a
mongoshmethod. This is not the documentation for a language-specific driver, such as Node.js.MongoDB API ドライバーについては、各言語の「MongoDB ドライバーのドキュメント」を参照してください。
次の値を返します。 ブール値
cursor.isExhausted()returnsfalseif documents remain in the current document batch read by the cursor. Otherwise, returnstrue.
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
- 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()は使用できません。 代わりに、次の有無を確認します。
ドキュメントが変更ストリーム カーソル内に残っている場合は、
cursor.tryNext()を使用します。変更ストリーム カーソルが閉じている場合は、
cursor.isClosed()を使用します。
変更ストリームの例については、「監視の例」と「変更ストリーム イメージの例 」を参照してください。
例
このセクションには、カーソルを使用して、気象センサーからの温度読み取り値を持つドキュメントを読み取る例が含まれています。 You'll see examples of isExhausted().