Hello,
I am getting cursorTimeout error, so I increased cursorTimeoutMillis .
I am aware that the default timeout is 10min, but strange is, on one cluster it is working fine and on another identical cluster it is giving me this cursor not found.
I am not sure why my timeout setting is not working.
Why same query with same data is not giving that error. The error-free cluster is trafic free and kind of test cluster, does that also matter?
Hi Ayush,
Could you refer the links below
https://jira.mongodb.org/browse/SERVER-34053
opened 01:00PM - 25 Mar 20 UTC
closed 04:34PM - 12 Apr 20 UTC
docs
**Do you want to request a *feature* or report a *bug*?**
Report a bug
**Wha… t is the current behavior?**
I recently bumped my Mongoose version from 5.5.7 to 5.9.6 and I spotted a issue with cursors.
The error is `MongoError: cursor id XXX not found` (even with `cursor.addCursorFlag('noCursorTimeout', true)`.
**If the current behavior is a bug, please provide the steps to reproduce.**
You can reproduce the bug by running this script (for a few hours) :
```
const mongoose = require('mongoose');
const sleep = seconds => new Promise(resolve => setTimeout(resolve, seconds * 1000));
(async () => {
await mongoose.connect('mongodb://localhost/test', { useCreateIndex: true, useNewUrlParser: true, useUnifiedTopology: true, poolSize: 10 });
const Doc = mongoose.model('Test', new mongoose.Schema({
counter: { type: Number, default: 0 }
}));
for(let i = 0; i < 10000; ++i)
await (new Doc()).save();
const cursor = Doc.find({}).cursor();
cursor.addCursorFlag('noCursorTimeout', true);
await cursor.eachAsync(async doc => {
doc.counter++;
await doc.save();
console.log(`Doc ${doc._id} saved, sleeping for 10 seconds...`);
await sleep(10);
});
await cursor.close();
})();
```
**What is the expected behavior?**
The error must not occur.
**What are the versions of Node.js, Mongoose and MongoDB you are using?**
Node v12.16.1
Mongoose v5.9.6
MongoDB v4.0.16
I think the error has to do with the MongoDB idle session timeout (https://docs.mongodb.com/manual/reference/method/cursor.noCursorTimeout/) but I am no expert.
Cheers