diff --git a/src/bulk/common.ts b/src/bulk/common.ts index 068a1b4611..4afcecf20c 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -105,12 +105,9 @@ export interface UpdateManyModel { /** @public */ export type AnyBulkWriteOperation = | { insertOne: InsertOneModel } - | { insertMany: Document[] } | { replaceOne: ReplaceOneModel } | { updateOne: UpdateOneModel } | { updateMany: UpdateManyModel } - | { removeOne: DeleteOneModel } - | { removeMany: DeleteManyModel } | { deleteOne: DeleteOneModel } | { deleteMany: DeleteManyModel }; @@ -786,14 +783,6 @@ export class FindOperators { ); } - removeOne(): BulkOperationBase { - return this.deleteOne(); - } - - remove(): BulkOperationBase { - return this.delete(); - } - /** Upsert modifier for update bulk operation, noting that this operation is an upsert. */ upsert(): this { if (!this.bulkOperation.s.currentOp) { @@ -1070,12 +1059,6 @@ export abstract class BulkOperationBase { return this.addToOperationsList(BatchType.INSERT, op.insertOne.document); } - // NOTE: incompatible with CRUD specification, consider removing - if ('insertMany' in op) { - op.insertMany.forEach(insertOp => this.raw({ insertOne: { document: insertOp } })); - return this; - } - if ('replaceOne' in op || 'updateOne' in op || 'updateMany' in op) { if ('replaceOne' in op) { if ('q' in op.replaceOne) { @@ -1121,20 +1104,6 @@ export abstract class BulkOperationBase { } } - if ('removeOne' in op) { - return this.addToOperationsList( - BatchType.DELETE, - makeDeleteStatement(op.removeOne.filter, { ...op.removeOne, limit: 1 }) - ); - } - - if ('removeMany' in op) { - return this.addToOperationsList( - BatchType.DELETE, - makeDeleteStatement(op.removeMany.filter, { ...op.removeMany, limit: 0 }) - ); - } - if ('deleteOne' in op) { if ('q' in op.deleteOne) { throw new TypeError('Raw operations are not allowed'); @@ -1157,7 +1126,7 @@ export abstract class BulkOperationBase { // otherwise an unknown operation was provided throw TypeError( - 'bulkWrite only supports insertOne, insertMany, updateOne, updateMany, removeOne, removeMany, deleteOne, deleteMany' + 'bulkWrite only supports insertOne, updateOne, updateMany, deleteOne, deleteMany' ); } diff --git a/src/collection.ts b/src/collection.ts index 188ddab24a..c4aadb3050 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -314,8 +314,6 @@ export class Collection { * ```js * { insertOne: { document: { a: 1 } } } * - * { insertMany: [{ g: 1 }, { g: 2 }]} - * * { updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } } * * { updateMany: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } } @@ -326,7 +324,7 @@ export class Collection { * * { deleteMany: { filter: {c:1} } } * - * { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true}} + * { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true} } *``` * Please note that raw operations are no longer accepted as of driver version 4.0. * diff --git a/src/operations/insert.ts b/src/operations/insert.ts index 17a9ee1b5b..6a78624098 100644 --- a/src/operations/insert.ts +++ b/src/operations/insert.ts @@ -113,7 +113,7 @@ export class InsertManyOperation extends AbstractOperation { const writeConcern = WriteConcern.fromOptions(options); const bulkWriteOperation = new BulkWriteOperation( coll, - [{ insertMany: prepareDocs(coll, this.docs, options) }], + prepareDocs(coll, this.docs, options).map(document => ({ insertOne: { document } })), options ); diff --git a/test/functional/bulk.test.js b/test/functional/bulk.test.js index 3e0545fb9e..3260e937c5 100644 --- a/test/functional/bulk.test.js +++ b/test/functional/bulk.test.js @@ -629,7 +629,7 @@ describe('Bulk', function () { } bulk.find({ b: 1 }).upsert().update({ b: 1 }); - bulk.find({ c: 1 }).remove(); + bulk.find({ c: 1 }).delete(); bulk.execute({ writeConcern: { w: 0 } }, function (err, result) { expect(err).to.not.exist; @@ -1135,7 +1135,7 @@ describe('Bulk', function () { } bulk.find({ b: 1 }).upsert().update({ b: 1 }); - bulk.find({ c: 1 }).remove(); + bulk.find({ c: 1 }).delete(); bulk.execute({ writeConcern: { w: 0 } }, function (err, result) { expect(err).to.not.exist; @@ -1917,8 +1917,8 @@ describe('Bulk', function () { bulk.find({ b: 3 }).collation({ locale: locales[2] }).replaceOne({ b: 2 }); // deletes - bulk.find({ b: 2 }).collation({ locale: locales[0] }).removeOne(); - bulk.find({ b: 1 }).collation({ locale: locales[1] }).remove(); + bulk.find({ b: 2 }).collation({ locale: locales[0] }).deleteOne(); + bulk.find({ b: 1 }).collation({ locale: locales[1] }).delete(); bulk.execute(err => { expect(err).to.not.exist; diff --git a/test/functional/crud_api.test.js b/test/functional/crud_api.test.js index 6c99c4faca..ddbffb0063 100644 --- a/test/functional/crud_api.test.js +++ b/test/functional/crud_api.test.js @@ -358,7 +358,8 @@ describe('CRUD API', function () { db.collection('t2_5').bulkWrite( [ { insertOne: { document: { a: 1 } } }, - { insertMany: [{ g: 1 }, { g: 2 }] }, + { insertOne: { document: { g: 1 } } }, + { insertOne: { document: { g: 2 } } }, { updateOne: { filter: { a: 2 }, update: { $set: { a: 2 } }, upsert: true } }, { updateMany: { filter: { a: 2 }, update: { $set: { a: 2 } }, upsert: true } }, { deleteOne: { filter: { c: 1 } } }, @@ -443,7 +444,8 @@ describe('CRUD API', function () { db.collection('t2_7').bulkWrite( [ { insertOne: { document: { a: 1 } } }, - { insertMany: [{ g: 1 }, { g: 2 }] }, + { insertOne: { document: { g: 1 } } }, + { insertOne: { document: { g: 2 } } }, { updateOne: { filter: { a: 2 }, update: { $set: { a: 2 } }, upsert: true } }, { updateMany: { filter: { a: 2 }, update: { $set: { a: 2 } }, upsert: true } }, { deleteOne: { filter: { c: 1 } } }, diff --git a/test/functional/operation_example.test.js b/test/functional/operation_example.test.js index f445eeaa21..36a9cbb827 100644 --- a/test/functional/operation_example.test.js +++ b/test/functional/operation_example.test.js @@ -5903,7 +5903,7 @@ describe('Operation Examples', function () { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations batch.execute(function (err, result) { @@ -5969,7 +5969,7 @@ describe('Operation Examples', function () { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations batch.execute(function (err, result) { diff --git a/test/functional/operation_generators_example.test.js b/test/functional/operation_generators_example.test.js index 9c89bdf053..73802e6d8d 100644 --- a/test/functional/operation_generators_example.test.js +++ b/test/functional/operation_generators_example.test.js @@ -3861,7 +3861,7 @@ describe('Operation (Generators)', function () { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations var result = yield batch.execute(); @@ -3932,7 +3932,7 @@ describe('Operation (Generators)', function () { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations var result = yield batch.execute(); diff --git a/test/functional/operation_promises_example.test.js b/test/functional/operation_promises_example.test.js index 0422db2016..7897cd1cd9 100644 --- a/test/functional/operation_promises_example.test.js +++ b/test/functional/operation_promises_example.test.js @@ -4241,7 +4241,7 @@ describe('Operation (Promises)', function () { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations return batch.execute().then(function (result) { @@ -4308,7 +4308,7 @@ describe('Operation (Promises)', function () { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations return batch.execute().then(function (result) {