无法对游标运行getMore



我有一个非常简单的MongoDBfind查询,它在一个字段上过滤一个相当大的集合。

let client = new MongoClient(`mongodb://${ip}:27019/test`, { w: 0 })
client.connect()
const db = client.db(dbName)
const messages = db.collection('messages')
;(async () => {
for (let i = 0; i < 10; i++) {
const cursor = messages.find({ deviceId: '786b06a838163326023e7726bd6f42481cc6b1ab' })
const allValues = await cursor.toArray()
console.log(allValues)
cursor.close()
}
})()

运行一次查询效果良好。但是,当我尝试按顺序多次运行它时,它会立即返回此错误,而不会返回任何其他结果。

MongoServerError: Cannot run getMore on cursor 2366016547291243997, which was not created in a session, in session 6c5c71bf-88b2-45d7-b234-bf7bb93554b8 - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=
at MessageStream.messageHandler (/home/tobias/Github/BachelorArbeit/node_modules/mongodb/lib/cmap/connection.js:462:30)
at MessageStream.emit (node:events:390:28)
at processIncomingData (/home/tobias/Github/BachelorArbeit/node_modules/mongodb/lib/cmap/message_stream.js:108:16)
at MessageStream._write (/home/tobias/Github/BachelorArbeit/node_modules/mongodb/lib/cmap/message_stream.js:28:9)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at MessageStream.Writable.write (node:internal/streams/writable:334:10)
at Socket.ondata (node:internal/streams/readable:754:22)
at Socket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:315:12) {
ok: 0,
code: 50799,
codeName: 'Location50799',
'$clusterTime': {
clusterTime: Timestamp { low: 2, high: 1643509041, unsigned: true },
signature: {
hash: Binary {
sub_type: 0,
buffer: Buffer(20) [Uint8Array] [
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
],
position: 20
},
keyId: 0
}
},
operationTime: Timestamp { low: 2, high: 1643509041, unsigned: true }
}

奇怪的是,当我设置像100这样的低limit时,它就起作用了。

在谷歌上搜索这个问题并查看其他出现此错误的StackOverflow帖子并没有帮助。我在这里错过了什么?

将Write Concern指定为0是个问题(我不知道为什么(

let client = new MongoClient(`mongodb://${ip}:27019/test`, { w: 1 })

将其更改为1或默认值解决了问题。

最新更新