mongodb/node-mongodb-native · error · MongoInvalidArgumentError
Cannot request unacknowledged write concern and ordered…
Error message
Cannot request unacknowledged write concern and ordered writes
What it means
Thrown when bulk write options combine writeConcern w:0 (unacknowledged) with ordered: true. Because ordered writes wait for each batch to be acknowledged before sending the next, ordering is meaningless without acknowledgements; the driver requires ordered: false when w is 0.
Solutions
- Pair w:0 with ordered: false: client.bulkWrite(models, { writeConcern: { w: 0 }, ordered: false }).
- Or keep ordered writes by using an acknowledged write concern (omit w:0).
- Remember ordered defaults to true — you must explicitly opt out when w is 0.
Example fix
// before
await client.bulkWrite(models, { writeConcern: { w: 0 } }); // ordered defaults to true
// after
await client.bulkWrite(models, { writeConcern: { w: 0 }, ordered: false }); Defensive patterns
Strategy: validation
Validate before calling
if (options?.writeConcern?.w === 0 && (options?.ordered ?? true)) {
throw new Error('w:0 requires ordered:false');
}
await client.bulkWrite(models, { ...options, ordered: options?.writeConcern?.w === 0 ? false : (options?.ordered ?? true) }); Prevention
- Whenever you set w=0 (in URI or options), set ordered:false in the same edit.
- Audit connection strings for w=0 and review all bulkWrite call sites.
When it happens
Trigger: Calling client.bulkWrite(models, { writeConcern: { w: 0 } }) without overriding ordered — the default for ordered is true, so the check fails immediately. Same outcome if you set both w:0 and ordered: true explicitly.
Common situations: Setting w=0 in the connection string for throughput and then calling bulkWrite without options; performance tuning that drops acknowledgement but forgets to relax ordering.
Related errors
- Cannot request unacknowledged write concern and verbose…
- write operation failed
- Argument "operations" must be an array of documents
- authMechanism not supported
- Bulk find operation must specify a selector
AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11).
Data as JSON: /api/errors/bb2ad7334110bc80.
Report an issue: GitHub.
Appendix: 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 dce7939f86)