{"record":{"id":"292704aeafdd89d8","repo":"mongodb/node-mongodb-native","slug":"cursor-document-did-not-contain-a-batch","errorCode":null,"errorMessage":"Cursor document did not contain a batch","messagePattern":"Cursor document did not contain a batch","errorType":"exception","errorClass":"MongoUnexpectedServerResponseError","httpStatus":null,"severity":"error","filePath":"src/cmap/wire_protocol/responses.ts","lineNumber":277,"sourceCode":"    if (namespace != null) return ns(namespace);\n    return null;\n  }\n\n  public get length() {\n    return Math.max(this.batchSize - this.iterated, 0);\n  }\n\n  private _encryptedBatch: OnDemandDocument | null = null;\n  get encryptedBatch() {\n    if (this.encryptedResponse == null) return null;\n    if (this._encryptedBatch != null) return this._encryptedBatch;\n\n    const cursor = this.encryptedResponse?.get('cursor', BSONType.object);\n    if (cursor?.has('firstBatch'))\n      this._encryptedBatch = cursor.get('firstBatch', BSONType.array, true);\n    else if (cursor?.has('nextBatch'))\n      this._encryptedBatch = cursor.get('nextBatch', BSONType.array, true);\n    else throw new MongoUnexpectedServerResponseError('Cursor document did not contain a batch');\n\n    return this._encryptedBatch;\n  }\n\n  private get batch() {\n    if (this._batch != null) return this._batch;\n    const cursor = this.cursor;\n    if (cursor.has('firstBatch')) this._batch = cursor.get('firstBatch', BSONType.array, true);\n    else if (cursor.has('nextBatch')) this._batch = cursor.get('nextBatch', BSONType.array, true);\n    else throw new MongoUnexpectedServerResponseError('Cursor document did not contain a batch');\n    return this._batch;\n  }\n\n  public get batchSize() {\n    return this.batch?.size();\n  }\n\n  public get postBatchResumeToken() {","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/wire_protocol/responses.ts#L259-L295","documentation":"Thrown by the encryptedBatch getter on CursorResponse when CSFLE/Queryable Encryption is active and the encrypted server response's cursor document contains neither a firstBatch nor a nextBatch array. The driver needs one of these to walk decrypted documents, so it raises a MongoUnexpectedServerResponseError. This path only runs when encryption result decoration is enabled.","triggerScenarios":"Fires at src/cmap/wire_protocol/responses.ts:277 when encryptedResponse is set (CSFLE/QE in use) and `cursor.has('firstBatch')` and `cursor.has('nextBatch')` are both false. Occurs while iterating a cursor whose encrypted payload has an unexpected shape.","commonSituations":"A malformed encrypted response from the server; mongocrypt/libmongocrypt version incompatibility with the server; a proxy altering the encrypted frame; a server bug in CSFLE/QE response construction. Specific to deployments using client-side encryption.","solutions":["Ensure mongodb-client-encryption and libmongocrypt versions match the driver's requirements.","Upgrade the driver and server to compatible CSFLE/QE-capable releases.","Disable any proxy that may rewrite encrypted responses.","Report with the encryption schema and server version if reproducible."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  for await (const doc of encryptedCollection.find({})) {  }\n} catch (error) {\n  if (error instanceof MongoUnexpectedServerResponseError && /did not contain a batch/.test(error.message)) {\n  }\n}","preventionTips":["Use mongodb-client-encryption and libmongocrypt versions required by the driver.","Keep driver, server, and crypt_shared versions aligned.","Avoid intermediaries that alter encrypted frames."],"tags":["csfle","encryption","cursor","wire-protocol"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}