mongodb/node-mongodb-native · error · MongoInvalidArgumentError

Cannot request unacknowledged write concern and verbose resu

Error message

Cannot request unacknowledged write concern and verbose results

What it means

Thrown by the ClientBulkWriteExecutor constructor when write concern w:0 (unacknowledged) is combined with verboseResults: true. Unacknowledged writes receive no per-document results, so requesting verbose results is contradictory. MongoInvalidArgumentError fires before execution.

Source

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

    }

    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) {
        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> {

View on GitHub (pinned to 3366c21a63)

Solutions

  1. Drop verboseResults when using w:0, since no per-doc results are returned.
  2. Use an acknowledged write concern (w:1 or majority) if you need verbose per-document results.
  3. Resolve the effective write concern: if client.s.options has w:0, do not pass verboseResults.

Example fix

// before
await client.bulkWrite(models, {
  writeConcern: { w: 0 },
  verboseResults: true // throws
});

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

Strategy: validation

Validate before calling

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

Type guard

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

Prevention

When it happens

Trigger: Calling client.bulkWrite(models, { writeConcern: { w: 0 }, verboseResults: true }); also when a client-level w:0 write concern is inherited and verboseResults is enabled.

Common situations: Enabling verboseResults for debugging while the client/connection string sets w:0 for throughput; inheriting an unacknowledged write concern from the client and turning on verbose results.

Related errors


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