{"id":"bb2ad7334110bc80","repo":"mongodb/node-mongodb-native","slug":"cannot-request-unacknowledged-write-concern-and-or","errorCode":null,"errorMessage":"Cannot request unacknowledged write concern and ordered writes","messagePattern":"Cannot request unacknowledged write concern and ordered writes","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/operations/client_bulk_write/executor.ts","lineNumber":70,"sourceCode":"      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) {\n        throw new MongoInvalidArgumentError(\n          'Cannot request unacknowledged write concern and verbose results'\n        );\n      }\n\n      if (this.options.ordered) {\n        throw new MongoInvalidArgumentError(\n          'Cannot request unacknowledged write concern and ordered writes'\n        );\n      }\n    }\n  }\n\n  /**\n   * Execute the client bulk write. Will split commands into batches and exhaust the cursors\n   * for each, then merge the results into one.\n   * @returns The result.\n   */\n  async execute(): Promise<ClientBulkWriteResult> {\n    // The command builder will take the user provided models and potential split the batch\n    // into multiple commands due to size.\n    const pkFactory = this.client.s.options.pkFactory;\n    const commandBuilder = new ClientBulkWriteCommandBuilder(\n      this.operations,\n      this.options,","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/operations/client_bulk_write/executor.ts#L52-L88","documentation":"Thrown by the ClientBulkWriteExecutor constructor when write concern w:0 (unacknowledged) is combined with ordered: true. With unacknowledged writes the server does not report per-document errors, so ordered semantics (stop on first error) cannot be honored; ordered also defaults to true, making this easy to hit. MongoInvalidArgumentError.","triggerScenarios":"Calling client.bulkWrite(models, { writeConcern: { w: 0 } }) without setting ordered:false (ordered defaults to true); explicitly setting ordered:true with w:0.","commonSituations":"Inheriting w:0 from the connection string for fire-and-forget writes and forgetting to set ordered:false; high-throughput ingestion tuned with w:0.","solutions":["Set ordered:false when using w:0: client.bulkWrite(models, { writeConcern: { w: 0 }, ordered: false }).","Switch to an acknowledged write concern (w:1+) if you need ordered behavior.","Check the effective write concern from the client and force ordered:false accordingly."],"exampleFix":"// before\nawait client.bulkWrite(models, { writeConcern: { w: 0 } }); // ordered defaults true -> throws\n\n// after\nawait client.bulkWrite(models, {\n  writeConcern: { w: 0 },\n  ordered: false\n});","handlingStrategy":"validation","validationCode":"if (options.writeConcern?.w === 0) options.ordered = false;","typeGuard":"function isUnacknowledged(wc): boolean { return wc?.w === 0; }","tryCatchPattern":null,"preventionTips":["Always set ordered:false with w:0 (ordered defaults true)","Check inherited client write concern","Prefer acknowledged writes when ordering matters"],"tags":["bulk-write","write-concern","client-bulk-write","options-conflict","ordered"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}