{"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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/mongo_client.ts#L562-L598","documentation":"Thrown by MongoClient.bulkWrite() (the client-level bulk write across namespaces) when the client was constructed with an autoEncrypter (CSFLE/Queryable Encryption auto-encryption enabled). Client-side field-level encryption cannot currently intercept client-level bulk writes, so the combination is explicitly rejected as MongoInvalidArgumentError before any network call.","triggerScenarios":"Constructing MongoClient with autoEncryption: { ... } in options and then calling client.bulkWrite(models). Using a shared encrypted client for the new bulkWrite API.","commonSituations":"Adopting the client.bulkWrite() API (server 8.0+) on an app already using CSFLE for compliance; shared client factories that attach autoEncryption to every client.","solutions":["Use a SEPARATE MongoClient without autoEncryption for client.bulkWrite(), keeping encryption on the per-collection client.","Fall back to per-collection collection.bulkWrite() on the encrypted client (auto-encryption IS supported there).","Disable autoEncryption for the workload that needs client.bulkWrite() if encryption is not mandatory for those writes."],"exampleFix":"// before\nconst client = new MongoClient(uri, { autoEncryption: { ... } });\nawait client.bulkWrite(models); // throws\n\n// after\nconst encClient = new MongoClient(uri, { autoEncryption: { ... } });\nconst plainClient = new MongoClient(uri);\nawait plainClient.bulkWrite(models);","handlingStrategy":"validation","validationCode":"function canClientBulkWrite(client) {\n  return !client.autoEncrypter;\n}","typeGuard":"function hasAutoEncryption(client): boolean {\n  return !!client.s.options.autoEncryption;\n}","tryCatchPattern":"try { await client.bulkWrite(models); } catch (e) {\n  if (e instanceof MongoInvalidArgumentError && /automatic encryption/.test(e.message)) {\n    await plainClient.bulkWrite(models); // separate non-encrypting client\n    return;\n  }\n  throw e;\n}","preventionTips":["Keep a dedicated non-encrypting client for client.bulkWrite","Fall back to collection.bulkWrite on the encrypted client","Detect autoEncryption in client factory and branch the API"],"tags":["bulk-write","csfle","client-side-encryption","auto-encryption"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}