mongodb/node-mongodb-native · error · MongoClientBulkWriteExecutionError
No client bulk write models were provided.
Error message
No client bulk write models were provided.
What it means
Thrown by the ClientBulkWriteExecutor constructor when the models array is empty. There is nothing to send, so the executor refuses to construct an empty command. Classified as MongoClientBulkWriteExecutionError (a distinct error type for client bulk write execution failures).
Source
Thrown at src/operations/client_bulk_write/executor.ts:45
*/
export class ClientBulkWriteExecutor {
private readonly client: MongoClient;
private readonly options: ClientBulkWriteOptions;
private readonly operations: ReadonlyArray<AnyClientBulkWriteModel<Document>>;
/**
* Instantiate the executor.
* @param client - The mongo client.
* @param operations - The user supplied bulk write models.
* @param options - The bulk write options.
*/
constructor(
client: MongoClient,
operations: ReadonlyArray<AnyClientBulkWriteModel<Document>>,
options?: ClientBulkWriteOptions
) {
if (operations.length === 0) {
throw new MongoClientBulkWriteExecutionError('No client bulk write models were provided.');
}
this.client = client;
this.operations = operations;
this.options = {
ordered: true,
bypassDocumentValidation: false,
verboseResults: false,
...options
};
// If no write concern was provided, we inherit one from the client.
if (!this.options.writeConcern) {
this.options.writeConcern = WriteConcern.fromOptions(this.client.s.options);
}
if (this.options.writeConcern?.w === 0) {
if (this.options.verboseResults) {View on GitHub (pinned to 3366c21a63)
Solutions
- Guard the call: if (models.length > 0) await client.bulkWrite(models); else return empty result.
- Validate upstream so empty batches short-circuit before reaching bulkWrite.
- If models come from a map/filter, default to a no-op when the result is empty.
Example fix
// before
await client.bulkWrite(models); // throws if []
// after
if (models.length === 0) {
return { insertedCount: 0, updatedCount: 0, deletedCount: 0 };
}
await client.bulkWrite(models); Defensive patterns
Strategy: validation
Validate before calling
if (!Array.isArray(models) || models.length === 0) {
return { insertedCount: 0, updatedCount: 0, deletedCount: 0 };
} Type guard
function hasModels(arr): boolean { return Array.isArray(arr) && arr.length > 0; } Prevention
- Short-circuit empty batches before calling bulkWrite
- Filter/skip empty arrays in pipelines
- Return a synthetic empty result for no-op batches
When it happens
Trigger: Calling client.bulkWrite([]) directly; passing an array that was filtered down to zero elements; building models from an empty input list.
Common situations: Conditional/filtered write pipelines that produce no models; batch jobs where all input records were skipped; off-by-one slice producing [].
Related errors
- Client bulk write update models must only contain atomic mod
- Client bulk write replace models must not contain atomic mod
- Update document requires atomic operators
- Replacement document must not use atomic operators
- Bulk find operation must specify a selector
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/dfffd1fed0c25844.json.
Report an issue: GitHub.