我正在 Mongo 3.6.6 上运行(在小型 Mongo Atlas 集群上,未分片),使用本机 Node JS 驱动程序(v. 3.0.10)
我的代码如下所示:
const records = await collection.find({
userId: ObjectId(userId),
status: 'completed',
lastUpdated: {
$exists: true,
$gte: '2018-06-10T21:24:12.000Z'
}
}).toArray();
我偶尔会看到这个错误:
{
"name": "MongoError",
"message": "cursor id 16621292331349 not found",
"ok": 0,
"errmsg": "cursor id 16621292331349 not found",
"code": 43,
"codeName": "CursorNotFound",
"operationTime": "6581469650867978275",
"$clusterTime": {
"clusterTime": "6581469650867978275",
"signature": {
"hash": "aWuGeAxOib4XWr1AOoowQL8yBmQ=",
"keyId": "6547661618229018626"
}
}
}
对于最多返回几百条记录的查询会发生这种情况。每条记录有几百字节。
我在网上查找了问题所在,但是most of what I found正在谈论需要超过 10 分钟才能完成的非常大的操作的游标超时。我无法从日志中准确判断失败的查询花了多长时间,但最多是两秒(可能比这短得多)。
我测试了使用与出错的值相同的值运行查询以及执行时间explain
只有几毫秒:
"executionStats" : {
"executionSuccess" : true,
"nReturned" : NumberInt(248),
"executionTimeMillis" : NumberInt(3),
"totalKeysExamined" : NumberInt(741),
"totalDocsExamined" : NumberInt(741),
"executionStages" : {...}
},
"allPlansExecution" : []
]
}
有任何想法吗?间歇性网络延迟是否会导致此错误?我该如何缓解这种情况?谢谢