{"record":{"id":"dfffd1fed0c25844","repo":"mongodb/node-mongodb-native","slug":"no-client-bulk-write-models-were-provided","errorCode":null,"errorMessage":"No client bulk write models were provided.","messagePattern":"No client bulk write models were provided\\.","errorType":"exception","errorClass":"MongoClientBulkWriteExecutionError","httpStatus":null,"severity":"error","filePath":"src/operations/client_bulk_write/executor.ts","lineNumber":45,"sourceCode":" */\nexport class ClientBulkWriteExecutor {\n  private readonly client: MongoClient;\n  private readonly options: ClientBulkWriteOptions;\n  private readonly operations: ReadonlyArray<AnyClientBulkWriteModel<Document>>;\n\n  /**\n   * Instantiate the executor.\n   * @param client - The mongo client.\n   * @param operations - The user supplied bulk write models.\n   * @param options - The bulk write options.\n   */\n  constructor(\n    client: MongoClient,\n    operations: ReadonlyArray<AnyClientBulkWriteModel<Document>>,\n    options?: ClientBulkWriteOptions\n  ) {\n    if (operations.length === 0) {\n      throw new MongoClientBulkWriteExecutionError('No client bulk write models were provided.');\n    }\n\n    this.client = client;\n    this.operations = operations;\n    this.options = {\n      ordered: true,\n      bypassDocumentValidation: false,\n      verboseResults: false,\n      ...options\n    };\n\n    // If no write concern was provided, we inherit one from the client.\n    if (!this.options.writeConcern) {\n      this.options.writeConcern = WriteConcern.fromOptions(this.client.s.options);\n    }\n\n    if (this.options.writeConcern?.w === 0) {\n      if (this.options.verboseResults) {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/operations/client_bulk_write/executor.ts#L27-L63","documentation":"Thrown by the client bulk write executor when the models array is empty. The driver does not issue an empty bulkWrite command to the server because that would be a wasted round trip; instead it fails fast with this client-side error.","triggerScenarios":"Calling client.bulkWrite([]) directly, or passing an array that has been filtered down to zero elements before reaching bulkWrite.","commonSituations":"Building a models array conditionally and then calling bulkWrite without checking length; debouncing/batching code that fires on a timer even when no work accumulated; refactoring that drops the population step.","solutions":["Guard with if (models.length > 0) before calling client.bulkWrite(models).","Log a warning when a scheduled batch is empty — it usually signals an upstream logic gap.","If you expect this case often, wrap bulkWrite in a helper that short-circuits on empty input."],"exampleFix":"// before\nawait client.bulkWrite(models); // models may be []\n\n// after\nif (models.length === 0) return { insertedCount: 0, modifiedCount: 0 };\nawait client.bulkWrite(models);","handlingStrategy":"validation","validationCode":"if (!Array.isArray(models) || models.length === 0) {\n  return { insertedCount: 0, modifiedCount: 0, deletedCount: 0 };\n}\nawait client.bulkWrite(models);","typeGuard":"const hasModels = (v: unknown): v is unknown[] => Array.isArray(v) && v.length > 0;","tryCatchPattern":null,"preventionTips":["Guard bulkWrite calls with a length check.","Investigate empty batches in scheduler code — they usually indicate upstream bugs."],"tags":["bulk-write","validation","api-misuse"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}