对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

游标()(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.

您可以将isExhausted()与可追加游标一起使用。即使当前批处理中没有剩余文档,可追加游标也会保持打开状态。当没有剩余文档时,其他游标会自动关闭。

您不能将isExhausted()与change stream一起使用。相反,要检查是否:

有关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()的示例。

1

运行:

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

创建一个名为sensorCursor的游标变量,用于读取sensor集合中的文档:

var sensorCursor = db.sensor.find()
3

运行:

sensorCursor.count()

输出为2 ,因为collection中有两个文档。

4

运行:

sensorCursor.next()

输出:

{ _id: 0, temperature: 12 }
5

运行:

sensorCursor.isExhausted()

输出为false ,因为sensorCursor中有剩余文档。

6

运行:

sensorCursor.next()

输出:

{ _id: 1, temperature: 23 }
7

运行:

sensorCursor.next()

没有更多文档,该示例返回null 。

8

运行:

sensorCursor.isExhausted()

没有更多文档, isExhausted()返回true 。

给本页内容打分

在此页面上