Docs 菜单
Docs 主页
/
MongoDB Manual
/ / /

cursor.isExhausted()

在此页面上

  • 行为
  • 举例
cursor.isExhausted()

重要

mongosh 方法

这是一个 mongosh方法。 这不是Node.js或其他特定于编程语言的驱动程序方法的文档。

在大多数情况下, mongosh方法的工作方式与传统 mongo shell 方法相同。但是,某些旧方法在mongosh中不可用。

有关旧版mongo shell 文档,请参阅相应 MongoDB Server 版本的文档:

对于 MongoDB API 驱动程序,请参阅特定语言的MongoDB 驱动程序文档。

返回:布尔

如果文档仍在游标读取的当前文档批处理中, cursor.isExhausted()会返回false 。否则,返回true

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

您不能将isExhausted()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

后退

cursor.hint

来年

cursor.itcount

在此页面上