I know what a cursor is, and I’m aware that the default value of ‘cursorTimeoutMillis’ is 10 minutes.
I set the ‘cursorTimeoutMillis’ to 20 seconds and expected the cursor to timeout
if I sleep for more than 20 seconds.
However, the cursor did not timeout even when I slept for 15 minutes.
here’s my test scenario .
session 1
db.adminCommand({"getParameter":1 , "cursorTimeoutMillis":1})
db.adminCommand({"setParameter":1 , "cursorTimeoutMillis":20000})
var documentSize = (16 * 1024 * 1024)-64; // 16MB
var largeData = new Array(documentSize).join('x');
db.testCollection.insert({ data: largeData });
var largeData = new Array(documentSize).join('y');
db.testCollection.insert({ data: largeData });
var largeData = new Array(documentSize).join('z');
db.testCollection.insert({ data: largeData });
var myCursor = db.testCollection.find();
var count = 0;
while (myCursor.hasNext()) {
sleep(900000);
print(myCursor.isExhausted())
var document = myCursor.next();
count++;
printjson(count)
var a = document;
}
session 2
cursor: {
cursorId: Long("5249502433812123878"),
createdDate: ISODate("2023-08-06T04:04:58.746Z"),
lastAccessDate: ISODate("2023-08-06T04:04:58.746Z"),
nDocsReturned: Long("1"),
nBatchesReturned: Long("1"),
noCursorTimeout: false,
.
.
.
cursor: {
cursorId: Long("5249502433812123878"),
createdDate: ISODate("2023-08-06T04:04:58.746Z"),
lastAccessDate: ISODate("2023-08-06T04:19:58.812Z"),
nDocsReturned: Long("2"),
nBatchesReturned: Long("2"),
noCursorTimeout: false,
.
.
.
cursor: {
cursorId: Long("5249502433812123878"),
createdDate: ISODate("2023-08-06T04:04:58.746Z"),
lastAccessDate: ISODate("2023-08-06T04:34:58.868Z"),
nDocsReturned: Long("3"),
nBatchesReturned: Long("3"),
noCursorTimeout: false,
as you can see
The cursor timeout should be triggered,
but the cursor continues to remain active. Do you know why?