Cursor timeout in find stream() even after addCursorFlag in sharded collection

I am using sharded collection to stream data but it keep giving me cursorTimeOut even after putting addCursorFlag(“noCursorTimeout”, true).

How are you setting that flag? What does your code look like? Also what version of the driver are you using?

let cursor=await db.collection(“business”).find({}).sort({ _id: 1 }).addCursorFlag(“noCursorTimeout”, true);
while (await cursor.hasNext()) {
//process here
}

driver version is 4.5

Looking on SO, I did see a similar issue where they resolved it by passing the option as an option within the find:

db.collection(“business”).find({},{timeout: false}).sort({ _id: 1 })

I’ve had the cursor expire several times when running large scripts, typically when using one collection to feed the script data to perform other actions.
In those cases I typically use filter (not skip) and limits (with sorting!) to ensure that my cursor is short lived, just in case it times out or a fallover happens or something.

Oh Ok, make sense, I will filter the data up and process it in small batches.
Thanks

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.