On this page本页内容
cursor.
isExhausted
()¶mongo
Shell Method
This page documents the 本页记录了mongo
shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. mongo
shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。
Returns: | Boolean. |
---|
如果游标已关闭且批处理中没有剩余对象,则cursor.isExhausted()
returns true
if the cursor is closed and there are no remaining objects in the batch.cursor.isExhausted()
返回true
。
Use 使用isExhausted()
to support iterating cursors that remain open even if there are no documents remaining in the current batch, such as tailable
or change stream
cursors.isExhausted()
支持迭代即使当前批处理中没有剩余文档也保持打开状态的游标,例如tailable
游标或change stream
游标。
Consider the following 请考虑以下的while
loop iterating through updates to a change stream
cursor:while
循环,迭代变了对change stream
游标的更新:
A change stream cursor can return an empty batch if no new data changes have occured within a set period of time. 如果在设定的时间段内没有发生新的数据更改,则更改流游标可以返回空批。This causes the while loop to exit prematurely as 这会导致while循环过早退出,因为cursor.hasNext()
returns false
when it detects the empty batch. cursor.hasNext()
在检测到空批时返回false
。However, the change stream cursor is still open and able to return more documents in the future.但是,变更流游标仍然处于打开状态,将来可以返回更多文档。
Use 使用cursor.isExhausted()
to ensure the while loop only exits when the cursor is closed and there are no documents remaining in the batch:cursor.isExhausted()
确保while循环仅在游标关闭且批处理中没有剩余文档时退出: