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 版本
行为
可追加游标
您可以将isExhausted()与可追加游标一起使用。即使当前批处理中没有剩余文档,可追加游标也会保持打开状态。当没有剩余文档时,其他游标会自动关闭。
Change Streams
您不能将isExhausted()与change stream一起使用。相反,要检查是否:
文档保留在change stream游标中,请使用
cursor.tryNext()。change stream游标已关闭,请使用
cursor.isClosed()。
有关change stream示例,请参阅监视示例和change stream图像示例。
示例
This section contains examples that use a cursor to read documents from a collection with temperature readings from a weather sensor. 您将看到isExhausted()的示例。