mongodb/node-mongodb-native · error · MongoInvalidArgumentError

Cannot request unacknowledged write concern and ordered writ

Error message

Cannot request unacknowledged write concern and ordered writes

What it means

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.

Source

Thrown at src/operations/client_bulk_write/executor.ts:70

      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) {
        throw new MongoInvalidArgumentError(
          'Cannot request unacknowledged write concern and verbose results'
        );
      }

      if (this.options.ordered) {
        throw new MongoInvalidArgumentError(
          'Cannot request unacknowledged write concern and ordered writes'
        );
      }
    }
  }

  /**
   * Execute the client bulk write. Will split commands into batches and exhaust the cursors
   * for each, then merge the results into one.
   * @returns The result.
   */
  async execute(): Promise<ClientBulkWriteResult> {
    // The command builder will take the user provided models and potential split the batch
    // into multiple commands due to size.
    const pkFactory = this.client.s.options.pkFactory;
    const commandBuilder = new ClientBulkWriteCommandBuilder(
      this.operations,
      this.options,

View on GitHub (pinned to 3366c21a63)

Solutions

  1. Set ordered:false when using w:0: client.bulkWrite(models, { writeConcern: { w: 0 }, ordered: false }).
  2. Switch to an acknowledged write concern (w:1+) if you need ordered behavior.
  3. Check the effective write concern from the client and force ordered:false accordingly.

Example fix

// before
await client.bulkWrite(models, { writeConcern: { w: 0 } }); // ordered defaults true -> throws

// after
await client.bulkWrite(models, {
  writeConcern: { w: 0 },
  ordered: false
});
Defensive patterns

Strategy: validation

Validate before calling

if (options.writeConcern?.w === 0) options.ordered = false;

Type guard

function isUnacknowledged(wc): boolean { return wc?.w === 0; }

Prevention

When it happens

Trigger: Calling client.bulkWrite(models, { writeConcern: { w: 0 } }) without setting ordered:false (ordered defaults to true); explicitly setting ordered:true with w:0.

Common situations: 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.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04). Data as JSON: /data/errors/bb2ad7334110bc80.json. Report an issue: GitHub.