mongodb/node-mongodb-native · error · MongoInvalidArgumentError

bulkWrite only supports insertOne, updateOne, updateMany, de

Error message

bulkWrite only supports insertOne, updateOne, updateMany, deleteOne, deleteMany

What it means

Thrown by BulkOperationBase.raw() when an operation object does not contain any of the recognized operation keys (insertOne, updateOne, updateMany, replaceOne, deleteOne, deleteMany). After every known key is checked, the fall-through fires. bulkWrite/bulk only supports those six operation types.

Source

Thrown at src/bulk/common.ts:1152

      }
      return this.addToOperationsList(
        BatchType.DELETE,
        makeDeleteStatement(op.deleteOne.filter, { ...op.deleteOne, limit: 1 })
      );
    }

    if ('deleteMany' in op) {
      if ('q' in op.deleteMany) {
        throw new MongoInvalidArgumentError('Raw operations are not allowed');
      }
      return this.addToOperationsList(
        BatchType.DELETE,
        makeDeleteStatement(op.deleteMany.filter, { ...op.deleteMany, limit: 0 })
      );
    }

    // otherwise an unknown operation was provided
    throw new MongoInvalidArgumentError(
      'bulkWrite only supports insertOne, updateOne, updateMany, deleteOne, deleteMany'
    );
  }

  get length(): number {
    return this.s.currentIndex;
  }

  get bsonOptions(): BSONSerializeOptions {
    return this.s.bsonOptions;
  }

  get writeConcern(): WriteConcern | undefined {
    return this.s.writeConcern;
  }

  get batches(): Batch[] {
    const batches = [...this.s.batches];

View on GitHub (pinned to 3366c21a63)

Solutions

  1. Verify the operation key is one of: insertOne, updateOne, updateMany, replaceOne, deleteOne, deleteMany.
  2. Check for typos like 'udpateOne' or 'insertMany' (not supported; use multiple insertOne).
  3. Ensure each op object has exactly one operation key, not multiple.

Example fix

// before
bulk.raw({ udpateOne: { filter: { _id: 1 }, update: { $set: { a: 1 } } } });

// after
bulk.raw({ updateOne: { filter: { _id: 1 }, update: { $set: { a: 1 } } } });
Defensive patterns

Strategy: type-guard

Validate before calling

const BULK_OP_KEYS = ['insertOne','updateOne','updateMany','replaceOne','deleteOne','deleteMany'];
function isValidBulkOp(op) {
  if (op == null || typeof op !== 'object') return false;
  const present = BULK_OP_KEYS.filter(k => k in op);
  return present.length === 1;
}

Type guard

function isAnyBulkWriteOperation(op) {
  const keys = ['insertOne','updateOne','updateMany','replaceOne','deleteOne','deleteMany'];
  return op != null && typeof op === 'object' && keys.filter(k => k in op).length === 1;
}

Try / catch

try {
  bulk.raw(op);
} catch (e) {
  if (/only supports insertOne/.test(e.message)) {
    // log the offending op and its keys, then skip or fix
  }
}

Prevention

When it happens

Trigger: Passing a typo'd key like { udpateOne: {...} } or { insert: {...} } to bulk.raw(). Passing { replaceOne: {...}, updateOne: {...} } with multiple keys. Passing an object with no operation key at all.

Common situations: Typos in operation keys; building operations from unvalidated user input; version mismatches where an old operation shape (like insert) is used.

Related errors


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