{"record":{"id":"2ce76342f83de90e","repo":"mongodb/node-mongodb-native","slug":"mongoclient-bulkwrite-does-not-currently-support-a","errorCode":null,"errorMessage":"MongoClient bulkWrite does not currently support automatic encryption.","messagePattern":"MongoClient bulkWrite does not currently support automatic encryption\\.","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/mongo_client.ts","lineNumber":580,"sourceCode":"    return this.s.bsonOptions;\n  }\n\n  get timeoutMS(): number | undefined {\n    return this.s.options.timeoutMS;\n  }\n\n  /**\n   * Executes a client bulk write operation, available on server 8.0+.\n   * @param models - The client bulk write models.\n   * @param options - The client bulk write options.\n   * @returns A ClientBulkWriteResult for acknowledged writes and ok: 1 for unacknowledged writes.\n   */\n  async bulkWrite<SchemaMap extends Record<string, Document> = Record<string, Document>>(\n    models: ReadonlyArray<ClientBulkWriteModel<SchemaMap>>,\n    options?: ClientBulkWriteOptions\n  ): Promise<ClientBulkWriteResult> {\n    if (this.autoEncrypter) {\n      throw new MongoInvalidArgumentError(\n        'MongoClient bulkWrite does not currently support automatic encryption.'\n      );\n    }\n    // We do not need schema type information past this point (\"as any\" is fine)\n    return await new ClientBulkWriteExecutor(\n      this,\n      models as any,\n      resolveOptions(this, options)\n    ).execute();\n  }\n\n  /**\n   * An optional method to verify a handful of assumptions that are generally useful at application boot-time before using a MongoClient.\n   * For detailed information about the connect process see the MongoClient.connect static method documentation.\n   *\n   * @param url - The MongoDB connection string (supports `mongodb://` and `mongodb+srv://` schemes)\n   * @param options - Optional configuration options for the client\n   *","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/mongo_client.ts#L562-L598","documentation":"MongoClient.bulkWrite (src/mongo_client.ts:575) is the client-level bulk write API (server 8.0+). It explicitly refuses to run when the client has an autoEncrypter configured, throwing MongoInvalidArgumentError, because automatic encryption is not implemented for the client-level bulk write path. This is a product limitation, not a transient condition.","triggerScenarios":"Constructing new MongoClient(uri, { autoEncryption: {...} }) and then calling client.bulkWrite(models). Any attempt to combine CSFLE auto-encryption with the client-level bulkWrite helper.","commonSituations":"Enabling CSFLE globally on the client and then trying the new client.bulkWrite API for cross-collection writes. Migrating per-collection bulkWrite code to client.bulkWrite without realizing autoEncryption is incompatible.","solutions":["Use per-collection collection.bulkWrite() instead, which supports auto-encryption.","Perform client.bulkWrite on a separate MongoClient that does not have autoEncryption configured (only if the data does not require encryption).","If encryption is required, encrypt fields explicitly or route through a collection-level API."],"exampleFix":"// before\nconst client = new MongoClient(uri, { autoEncryption: {...} });\nawait client.bulkWrite([{ insertOne: { namespace: 'db.coll', document: {...} } }]);\n// after\nawait client.db('db').collection('coll').bulkWrite([{ insertOne: { document: {...} } }]);","handlingStrategy":"validation","validationCode":"function assertBulkWriteCompatible(autoEncrypter) {\n  if (autoEncrypter) {\n    throw new Error('client.bulkWrite is unavailable with autoEncryption; use collection.bulkWrite');\n  }\n}\n// or: detect at config time\nif (clientOptions.autoEncryption) delete clientOptions._useClientBulkWrite;","typeGuard":"function clientHasAutoEncryption(client: MongoClient): boolean {\n  return (client as any).autoEncrypter != null;\n}","tryCatchPattern":"try {\n  await client.bulkWrite(models);\n} catch (e) {\n  if (e instanceof MongoInvalidArgumentError && /automatic encryption/.test(e.message)) {\n    // route to collection.bulkWrite instead\n  } else throw e;\n}","preventionTips":["Do not enable autoEncryption on a MongoClient used for client.bulkWrite.","Keep a separate non-encrypted client for client-level bulk writes.","Route encrypted writes through collection-level bulkWrite."],"tags":["csfle","bulk-write","limitation","synchronous"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}