{"id":"5985a25b761fd284","repo":"mongodb/node-mongodb-native","slug":"bulkwrite-only-supports-insertone-updateone-upda","errorCode":null,"errorMessage":"bulkWrite only supports insertOne, updateOne, updateMany, deleteOne, deleteMany","messagePattern":"bulkWrite only supports insertOne, updateOne, updateMany, deleteOne, deleteMany","errorType":"validation","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/bulk/common.ts","lineNumber":1152,"sourceCode":"      }\n      return this.addToOperationsList(\n        BatchType.DELETE,\n        makeDeleteStatement(op.deleteOne.filter, { ...op.deleteOne, limit: 1 })\n      );\n    }\n\n    if ('deleteMany' in op) {\n      if ('q' in op.deleteMany) {\n        throw new MongoInvalidArgumentError('Raw operations are not allowed');\n      }\n      return this.addToOperationsList(\n        BatchType.DELETE,\n        makeDeleteStatement(op.deleteMany.filter, { ...op.deleteMany, limit: 0 })\n      );\n    }\n\n    // otherwise an unknown operation was provided\n    throw new MongoInvalidArgumentError(\n      'bulkWrite only supports insertOne, updateOne, updateMany, deleteOne, deleteMany'\n    );\n  }\n\n  get length(): number {\n    return this.s.currentIndex;\n  }\n\n  get bsonOptions(): BSONSerializeOptions {\n    return this.s.bsonOptions;\n  }\n\n  get writeConcern(): WriteConcern | undefined {\n    return this.s.writeConcern;\n  }\n\n  get batches(): Batch[] {\n    const batches = [...this.s.batches];","sourceCodeStart":1134,"sourceCodeEnd":1170,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/bulk/common.ts#L1134-L1170","documentation":"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.","triggerScenarios":"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.","commonSituations":"Typos in operation keys; building operations from unvalidated user input; version mismatches where an old operation shape (like insert) is used.","solutions":["Verify the operation key is one of: insertOne, updateOne, updateMany, replaceOne, deleteOne, deleteMany.","Check for typos like 'udpateOne' or 'insertMany' (not supported; use multiple insertOne).","Ensure each op object has exactly one operation key, not multiple."],"exampleFix":"// before\nbulk.raw({ udpateOne: { filter: { _id: 1 }, update: { $set: { a: 1 } } } });\n\n// after\nbulk.raw({ updateOne: { filter: { _id: 1 }, update: { $set: { a: 1 } } } });","handlingStrategy":"type-guard","validationCode":"const BULK_OP_KEYS = ['insertOne','updateOne','updateMany','replaceOne','deleteOne','deleteMany'];\nfunction isValidBulkOp(op) {\n  if (op == null || typeof op !== 'object') return false;\n  const present = BULK_OP_KEYS.filter(k => k in op);\n  return present.length === 1;\n}","typeGuard":"function isAnyBulkWriteOperation(op) {\n  const keys = ['insertOne','updateOne','updateMany','replaceOne','deleteOne','deleteMany'];\n  return op != null && typeof op === 'object' && keys.filter(k => k in op).length === 1;\n}","tryCatchPattern":"try {\n  bulk.raw(op);\n} catch (e) {\n  if (/only supports insertOne/.test(e.message)) {\n    // log the offending op and its keys, then skip or fix\n  }\n}","preventionTips":["Validate each op has exactly one of the six recognized keys before enqueueing.","Add a lint/unit test that catches common typos like 'udpateOne'.","Build operations through typed factory functions rather than hand-written literals."],"tags":["bulk-write","raw","argument-error","operation-key"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}