I have written a small node program using Mongoose to iterate over collection using a cursor. It has about 1800 documents and is hosted in Atlas. After quite a bit of time, I start getting a Mongo Error: Cursor ID not found.
My research indicates that the cursor may be timing out but not sure how that is possible considering the operations are pretty quick. I have tried setting the timeout option to false but get an error from Atlas saying that noTimeout options are not available on this tier.
I want the cursor to loop back to the beginning when it is done. I am running everything from a setInterval.
Any help would be greatly appreciated!
const timer = setInterval(async () => {
try {
person = cursor && (await cursor.next());
/* If the cursor exists get the next person, else get a new cursor */
if (person) {
//do stuff...
} else {
console.log('Acquiring cursor...');
cursor = await TwitterUser.find({}, '_id id_str name screen_name').cursor();
}
} catch (e) {
console.log(`Cursor error... ${e.stack}`);
}
}, 500);