mongodb/node-mongodb-native · error · MongoInvalidArgumentError
MongoClient bulkWrite does not currently support automatic e
Error message
MongoClient bulkWrite does not currently support automatic encryption.
What it means
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.
Source
Thrown at src/mongo_client.ts:580
return this.s.bsonOptions;
}
get timeoutMS(): number | undefined {
return this.s.options.timeoutMS;
}
/**
* Executes a client bulk write operation, available on server 8.0+.
* @param models - The client bulk write models.
* @param options - The client bulk write options.
* @returns A ClientBulkWriteResult for acknowledged writes and ok: 1 for unacknowledged writes.
*/
async bulkWrite<SchemaMap extends Record<string, Document> = Record<string, Document>>(
models: ReadonlyArray<ClientBulkWriteModel<SchemaMap>>,
options?: ClientBulkWriteOptions
): Promise<ClientBulkWriteResult> {
if (this.autoEncrypter) {
throw new MongoInvalidArgumentError(
'MongoClient bulkWrite does not currently support automatic encryption.'
);
}
// We do not need schema type information past this point ("as any" is fine)
return await new ClientBulkWriteExecutor(
this,
models as any,
resolveOptions(this, options)
).execute();
}
/**
* An optional method to verify a handful of assumptions that are generally useful at application boot-time before using a MongoClient.
* For detailed information about the connect process see the MongoClient.connect static method documentation.
*
* @param url - The MongoDB connection string (supports `mongodb://` and `mongodb+srv://` schemes)
* @param options - Optional configuration options for the client
*View on GitHub (pinned to 3366c21a63)
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.
Example fix
// before
const client = new MongoClient(uri, { autoEncryption: { ... } });
await client.bulkWrite(models); // throws
// after
const encClient = new MongoClient(uri, { autoEncryption: { ... } });
const plainClient = new MongoClient(uri);
await plainClient.bulkWrite(models); Defensive patterns
Strategy: validation
Validate before calling
function canClientBulkWrite(client) {
return !client.autoEncrypter;
} Type guard
function hasAutoEncryption(client): boolean {
return !!client.s.options.autoEncryption;
} Try / catch
try { await client.bulkWrite(models); } catch (e) {
if (e instanceof MongoInvalidArgumentError && /automatic encryption/.test(e.message)) {
await plainClient.bulkWrite(models); // separate non-encrypting client
return;
}
throw e;
} Prevention
- 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
When it happens
Trigger: Constructing MongoClient with autoEncryption: { ... } in options and then calling client.bulkWrite(models). Using a shared encrypted client for the new bulkWrite API.
Common situations: 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.
Related errors
- No AutoEncrypter available for encryption
- Update document requires atomic operators
- Replacement document must not use atomic operators
- Bulk find operation must specify a selector
- Operation must be an object with an operation key
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/2ce76342f83de90e.json.
Report an issue: GitHub.