Specifies a raw operation to perform in the bulk write.
(op: AnyBulkWriteOperation)
| 1035 | |
| 1036 | /** Specifies a raw operation to perform in the bulk write. */ |
| 1037 | raw(op: AnyBulkWriteOperation): this { |
| 1038 | if (op == null || typeof op !== class="st">'object') { |
| 1039 | throw new MongoInvalidArgumentError(class="st">'Operation must be an object with an operation key'); |
| 1040 | } |
| 1041 | if (class="st">'insertOne' in op) { |
| 1042 | const forceServerObjectId = this.shouldForceServerObjectId(); |
| 1043 | const document = |
| 1044 | op.insertOne && op.insertOne.document == null |
| 1045 | ? class="cm">// TODO(NODE-6003): remove support for omitting the `documents` subdocument in bulk inserts |
| 1046 | (op.insertOne as Document) |
| 1047 | : op.insertOne.document; |
| 1048 | |
| 1049 | maybeAddIdToDocuments(this.collection, document, { forceServerObjectId }); |
| 1050 | |
| 1051 | return this.addToOperationsList(BatchType.INSERT, document); |
| 1052 | } |
| 1053 | |
| 1054 | if (class="st">'replaceOne' in op || class="st">'updateOne' in op || class="st">'updateMany' in op) { |
| 1055 | if (class="st">'replaceOne' in op) { |
| 1056 | if (class="st">'q' in op.replaceOne) { |
| 1057 | throw new MongoInvalidArgumentError(class="st">'Raw operations are not allowed'); |
| 1058 | } |
| 1059 | const updateStatement = makeUpdateStatement( |
| 1060 | op.replaceOne.filter, |
| 1061 | op.replaceOne.replacement, |
| 1062 | { ...op.replaceOne, multi: false } |
| 1063 | ); |
| 1064 | if (hasAtomicOperators(updateStatement.u)) { |
| 1065 | throw new MongoInvalidArgumentError(class="st">'Replacement document must not use atomic operators'); |
| 1066 | } |
| 1067 | return this.addToOperationsList(BatchType.UPDATE, updateStatement); |
| 1068 | } |
| 1069 | |
| 1070 | if (class="st">'updateOne' in op) { |
| 1071 | if (class="st">'q' in op.updateOne) { |
| 1072 | throw new MongoInvalidArgumentError(class="st">'Raw operations are not allowed'); |
| 1073 | } |
| 1074 | const updateStatement = makeUpdateStatement(op.updateOne.filter, op.updateOne.update, { |
| 1075 | ...op.updateOne, |
| 1076 | multi: false |
| 1077 | }); |
| 1078 | if (!hasAtomicOperators(updateStatement.u, this.bsonOptions)) { |
| 1079 | throw new MongoInvalidArgumentError(class="st">'Update document requires atomic operators'); |
| 1080 | } |
| 1081 | return this.addToOperationsList(BatchType.UPDATE, updateStatement); |
| 1082 | } |
| 1083 | |
| 1084 | if (class="st">'updateMany' in op) { |
| 1085 | if (class="st">'q' in op.updateMany) { |
| 1086 | throw new MongoInvalidArgumentError(class="st">'Raw operations are not allowed'); |
| 1087 | } |
| 1088 | const updateStatement = makeUpdateStatement(op.updateMany.filter, op.updateMany.update, { |
| 1089 | ...op.updateMany, |
| 1090 | multi: true |
| 1091 | }); |
| 1092 | if (!hasAtomicOperators(updateStatement.u, this.bsonOptions)) { |
| 1093 | throw new MongoInvalidArgumentError(class="st">'Update document requires atomic operators'); |
| 1094 | } |
nothing calls this directly
no test coverage detected