From 39a3bd0dd83a5a2af8f88d5f8a1d279ba708a375 Mon Sep 17 00:00:00 2001 From: emadum Date: Thu, 29 Apr 2021 12:50:50 -0400 Subject: [PATCH 1/3] refactor!: remove deprecated bulk ops --- src/bulk/common.ts | 33 +------------------ src/operations/insert.ts | 2 +- test/functional/bulk.test.js | 8 ++--- test/functional/crud_api.test.js | 6 ++-- test/functional/operation_example.test.js | 4 +-- .../operation_generators_example.test.js | 4 +-- .../operation_promises_example.test.js | 4 +-- 7 files changed, 16 insertions(+), 45 deletions(-) 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/operations/insert.ts b/src/operations/insert.ts index 17a9ee1b5b..451b62bf72 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) { From bf7a2ab204c1d73171282069f5d06927231a60b4 Mon Sep 17 00:00:00 2001 From: emadum Date: Fri, 30 Apr 2021 11:43:19 -0400 Subject: [PATCH 2/3] fix lint --- src/operations/insert.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operations/insert.ts b/src/operations/insert.ts index 451b62bf72..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, - prepareDocs(coll, this.docs, options).map(document => ({ insertOne: { document }})), + prepareDocs(coll, this.docs, options).map(document => ({ insertOne: { document } })), options ); From 6ab1ad0065b4b1d2a1f33c27e82bb635219b4301 Mon Sep 17 00:00:00 2001 From: emadum Date: Mon, 3 May 2021 15:49:29 -0400 Subject: [PATCH 3/3] remove insertMany from bulkWrite docs --- src/collection.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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. *