[DOCS-15240] [Server] Open change streams iteration example script returns error from mongosh session Created: 13/Apr/22  Updated: 13/Nov/23  Resolved: 07/Sep/23

Status: Closed
Project: Documentation
Component/s: mongosh, Server
Affects Version/s: 5.0.6
Fix Version/s: 5.0.6, Server_Docs_20231030, Server_Docs_20231106, Server_Docs_20231105, Server_Docs_20231113

Type: Task Priority: Minor - P4
Reporter: Shane Smith Assignee: Lauren Tran
Resolution: Won't Do Votes: 1
Labels: quick-win, server-docs-bug-bash
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Sample Environment:
Mongodb Server 5.0.6
mongodb-mongosh-1.2.2-1.el7.x86_64


Participants:
Days since reply: 21 weeks, 6 days ago

 Description   

Summary: 

I found the example scripts listed in the below article to open a change stream are not compatible in a session using the mongosh binary.

https://www.mongodb.com/docs/v5.0/reference/method/db.collection.watch/#examples

The below error occurs when attempting to execute the cursor.IsExhausted() method on a change stream cursor opened within mongosh.

while (!watchCursor.isExhausted()){   if (watchCursor.hasNext()){      printjson(watchCursor.next());   }} 

MongoshInvalidInputError: isExhausted is not implemented for ChangeStreams because after closing a cursor, the remaining documents in the batch are no longer accessible. If you want to see if the cursor is closed use isClosed. If you want to see if there are documents left in the batch, use tryNext.

This script does work fine with the legacy mongo binary.

As a workaround with mongosh, I used the isClosed() method instead in the while loop like below:

while (!watchCursor.isClosed()) {  if (watchCursor.hasNext()){           printjson(watchCursor.next());    }}

Wondering here if the docs should be updated to note incompatibility of cursor.isExhausted() against a change stream cursor from mongosh, and/or suggest an alternate example of iterating the change stream cursor with mongosh.

 

 



 Comments   
Comment by Lauren Tran [ 07/Sep/23 ]

Requested change has already been made

Generated at Thu Feb 08 08:12:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.