Skip to content

Commit c3a1839

Browse files
authored
refactor(NODE-2978)!: remove deprecated bulk ops (#2794)
1 parent b45e3b3 commit c3a1839

8 files changed

+17
-48
lines changed

src/bulk/common.ts

+1-32
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,9 @@ export interface UpdateManyModel {
105105
/** @public */
106106
export type AnyBulkWriteOperation =
107107
| { insertOne: InsertOneModel }
108-
| { insertMany: Document[] }
109108
| { replaceOne: ReplaceOneModel }
110109
| { updateOne: UpdateOneModel }
111110
| { updateMany: UpdateManyModel }
112-
| { removeOne: DeleteOneModel }
113-
| { removeMany: DeleteManyModel }
114111
| { deleteOne: DeleteOneModel }
115112
| { deleteMany: DeleteManyModel };
116113

@@ -786,14 +783,6 @@ export class FindOperators {
786783
);
787784
}
788785

789-
removeOne(): BulkOperationBase {
790-
return this.deleteOne();
791-
}
792-
793-
remove(): BulkOperationBase {
794-
return this.delete();
795-
}
796-
797786
/** Upsert modifier for update bulk operation, noting that this operation is an upsert. */
798787
upsert(): this {
799788
if (!this.bulkOperation.s.currentOp) {
@@ -1070,12 +1059,6 @@ export abstract class BulkOperationBase {
10701059
return this.addToOperationsList(BatchType.INSERT, op.insertOne.document);
10711060
}
10721061

1073-
// NOTE: incompatible with CRUD specification, consider removing
1074-
if ('insertMany' in op) {
1075-
op.insertMany.forEach(insertOp => this.raw({ insertOne: { document: insertOp } }));
1076-
return this;
1077-
}
1078-
10791062
if ('replaceOne' in op || 'updateOne' in op || 'updateMany' in op) {
10801063
if ('replaceOne' in op) {
10811064
if ('q' in op.replaceOne) {
@@ -1121,20 +1104,6 @@ export abstract class BulkOperationBase {
11211104
}
11221105
}
11231106

1124-
if ('removeOne' in op) {
1125-
return this.addToOperationsList(
1126-
BatchType.DELETE,
1127-
makeDeleteStatement(op.removeOne.filter, { ...op.removeOne, limit: 1 })
1128-
);
1129-
}
1130-
1131-
if ('removeMany' in op) {
1132-
return this.addToOperationsList(
1133-
BatchType.DELETE,
1134-
makeDeleteStatement(op.removeMany.filter, { ...op.removeMany, limit: 0 })
1135-
);
1136-
}
1137-
11381107
if ('deleteOne' in op) {
11391108
if ('q' in op.deleteOne) {
11401109
throw new TypeError('Raw operations are not allowed');
@@ -1157,7 +1126,7 @@ export abstract class BulkOperationBase {
11571126

11581127
// otherwise an unknown operation was provided
11591128
throw TypeError(
1160-
'bulkWrite only supports insertOne, insertMany, updateOne, updateMany, removeOne, removeMany, deleteOne, deleteMany'
1129+
'bulkWrite only supports insertOne, updateOne, updateMany, deleteOne, deleteMany'
11611130
);
11621131
}
11631132

src/collection.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,6 @@ export class Collection {
314314
* ```js
315315
* { insertOne: { document: { a: 1 } } }
316316
*
317-
* { insertMany: [{ g: 1 }, { g: 2 }]}
318-
*
319317
* { updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
320318
*
321319
* { updateMany: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
@@ -326,7 +324,7 @@ export class Collection {
326324
*
327325
* { deleteMany: { filter: {c:1} } }
328326
*
329-
* { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true}}
327+
* { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true} }
330328
*```
331329
* Please note that raw operations are no longer accepted as of driver version 4.0.
332330
*

src/operations/insert.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class InsertManyOperation extends AbstractOperation<InsertManyResult> {
113113
const writeConcern = WriteConcern.fromOptions(options);
114114
const bulkWriteOperation = new BulkWriteOperation(
115115
coll,
116-
[{ insertMany: prepareDocs(coll, this.docs, options) }],
116+
prepareDocs(coll, this.docs, options).map(document => ({ insertOne: { document } })),
117117
options
118118
);
119119

test/functional/bulk.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ describe('Bulk', function () {
629629
}
630630

631631
bulk.find({ b: 1 }).upsert().update({ b: 1 });
632-
bulk.find({ c: 1 }).remove();
632+
bulk.find({ c: 1 }).delete();
633633

634634
bulk.execute({ writeConcern: { w: 0 } }, function (err, result) {
635635
expect(err).to.not.exist;
@@ -1135,7 +1135,7 @@ describe('Bulk', function () {
11351135
}
11361136

11371137
bulk.find({ b: 1 }).upsert().update({ b: 1 });
1138-
bulk.find({ c: 1 }).remove();
1138+
bulk.find({ c: 1 }).delete();
11391139

11401140
bulk.execute({ writeConcern: { w: 0 } }, function (err, result) {
11411141
expect(err).to.not.exist;
@@ -1917,8 +1917,8 @@ describe('Bulk', function () {
19171917
bulk.find({ b: 3 }).collation({ locale: locales[2] }).replaceOne({ b: 2 });
19181918

19191919
// deletes
1920-
bulk.find({ b: 2 }).collation({ locale: locales[0] }).removeOne();
1921-
bulk.find({ b: 1 }).collation({ locale: locales[1] }).remove();
1920+
bulk.find({ b: 2 }).collation({ locale: locales[0] }).deleteOne();
1921+
bulk.find({ b: 1 }).collation({ locale: locales[1] }).delete();
19221922

19231923
bulk.execute(err => {
19241924
expect(err).to.not.exist;

test/functional/crud_api.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ describe('CRUD API', function () {
358358
db.collection('t2_5').bulkWrite(
359359
[
360360
{ insertOne: { document: { a: 1 } } },
361-
{ insertMany: [{ g: 1 }, { g: 2 }] },
361+
{ insertOne: { document: { g: 1 } } },
362+
{ insertOne: { document: { g: 2 } } },
362363
{ updateOne: { filter: { a: 2 }, update: { $set: { a: 2 } }, upsert: true } },
363364
{ updateMany: { filter: { a: 2 }, update: { $set: { a: 2 } }, upsert: true } },
364365
{ deleteOne: { filter: { c: 1 } } },
@@ -443,7 +444,8 @@ describe('CRUD API', function () {
443444
db.collection('t2_7').bulkWrite(
444445
[
445446
{ insertOne: { document: { a: 1 } } },
446-
{ insertMany: [{ g: 1 }, { g: 2 }] },
447+
{ insertOne: { document: { g: 1 } } },
448+
{ insertOne: { document: { g: 2 } } },
447449
{ updateOne: { filter: { a: 2 }, update: { $set: { a: 2 } }, upsert: true } },
448450
{ updateMany: { filter: { a: 2 }, update: { $set: { a: 2 } }, upsert: true } },
449451
{ deleteOne: { filter: { c: 1 } } },

test/functional/operation_example.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5903,7 +5903,7 @@ describe('Operation Examples', function () {
59035903
.upsert()
59045904
.updateOne({ $set: { b: 2 } });
59055905
batch.insert({ a: 3 });
5906-
batch.find({ a: 3 }).remove({ a: 3 });
5906+
batch.find({ a: 3 }).delete({ a: 3 });
59075907

59085908
// Execute the operations
59095909
batch.execute(function (err, result) {
@@ -5969,7 +5969,7 @@ describe('Operation Examples', function () {
59695969
.upsert()
59705970
.updateOne({ $set: { b: 2 } });
59715971
batch.insert({ a: 3 });
5972-
batch.find({ a: 3 }).remove({ a: 3 });
5972+
batch.find({ a: 3 }).delete({ a: 3 });
59735973

59745974
// Execute the operations
59755975
batch.execute(function (err, result) {

test/functional/operation_generators_example.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3861,7 +3861,7 @@ describe('Operation (Generators)', function () {
38613861
.upsert()
38623862
.updateOne({ $set: { b: 2 } });
38633863
batch.insert({ a: 3 });
3864-
batch.find({ a: 3 }).remove({ a: 3 });
3864+
batch.find({ a: 3 }).delete({ a: 3 });
38653865

38663866
// Execute the operations
38673867
var result = yield batch.execute();
@@ -3932,7 +3932,7 @@ describe('Operation (Generators)', function () {
39323932
.upsert()
39333933
.updateOne({ $set: { b: 2 } });
39343934
batch.insert({ a: 3 });
3935-
batch.find({ a: 3 }).remove({ a: 3 });
3935+
batch.find({ a: 3 }).delete({ a: 3 });
39363936

39373937
// Execute the operations
39383938
var result = yield batch.execute();

test/functional/operation_promises_example.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4241,7 +4241,7 @@ describe('Operation (Promises)', function () {
42414241
.upsert()
42424242
.updateOne({ $set: { b: 2 } });
42434243
batch.insert({ a: 3 });
4244-
batch.find({ a: 3 }).remove({ a: 3 });
4244+
batch.find({ a: 3 }).delete({ a: 3 });
42454245

42464246
// Execute the operations
42474247
return batch.execute().then(function (result) {
@@ -4308,7 +4308,7 @@ describe('Operation (Promises)', function () {
43084308
.upsert()
43094309
.updateOne({ $set: { b: 2 } });
43104310
batch.insert({ a: 3 });
4311-
batch.find({ a: 3 }).remove({ a: 3 });
4311+
batch.find({ a: 3 }).delete({ a: 3 });
43124312

43134313
// Execute the operations
43144314
return batch.execute().then(function (result) {

0 commit comments

Comments
 (0)