Skip to content

Commit 2839e95

Browse files
authored
feat(NODE-4791): deprecate duplicate bulk methods (#3623)
1 parent 4b3e32d commit 2839e95

File tree

5 files changed

+102
-81
lines changed

5 files changed

+102
-81
lines changed

src/bulk/common.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,37 +212,58 @@ export class BulkWriteResult {
212212
return this.result.ok;
213213
}
214214

215-
/** The number of inserted documents */
215+
/**
216+
* The number of inserted documents
217+
* @deprecated Use insertedCount instead.
218+
*/
216219
get nInserted(): number {
217220
return this.result.nInserted;
218221
}
219222

220-
/** Number of upserted documents */
223+
/**
224+
* Number of upserted documents
225+
* @deprecated User upsertedCount instead.
226+
*/
221227
get nUpserted(): number {
222228
return this.result.nUpserted;
223229
}
224230

225-
/** Number of matched documents */
231+
/**
232+
* Number of matched documents
233+
* @deprecated Use matchedCount instead.
234+
*/
226235
get nMatched(): number {
227236
return this.result.nMatched;
228237
}
229238

230-
/** Number of documents updated physically on disk */
239+
/**
240+
* Number of documents updated physically on disk
241+
* @deprecated Use modifiedCount instead.
242+
*/
231243
get nModified(): number {
232244
return this.result.nModified;
233245
}
234246

235-
/** Number of removed documents */
247+
/**
248+
* Number of removed documents
249+
* @deprecated Use deletedCount instead.
250+
*/
236251
get nRemoved(): number {
237252
return this.result.nRemoved;
238253
}
239254

240-
/** Returns an array of all inserted ids */
255+
/**
256+
* Returns an array of all inserted ids
257+
* @deprecated Use insertedIds instead.
258+
*/
241259
getInsertedIds(): Document[] {
242260
return this.result.insertedIds;
243261
}
244262

245-
/** Returns an array of all upserted ids */
263+
/**
264+
* Returns an array of all upserted ids
265+
* @deprecated Use upsertedIds instead.
266+
*/
246267
getUpsertedIds(): Document[] {
247268
return this.result.upserted;
248269
}

test/integration/client-side-encryption/client_side_encryption.prose.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
19601960
);
19611961

19621962
expect(rewrapManyDataKeyResult).to.have.property('bulkWriteResult');
1963-
expect(rewrapManyDataKeyResult.bulkWriteResult).to.have.property('nModified', 1);
1963+
expect(rewrapManyDataKeyResult.bulkWriteResult).to.have.property('modifiedCount', 1);
19641964

19651965
// 7. Call ``clientEncryption1.decrypt`` with the ``ciphertext``. Assert the return value is "test".
19661966
const decryptResult1 = await clientEncryption1.decrypt(cipherText);

test/integration/crud/bulk.test.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('Bulk', function () {
161161
result = err.result;
162162

163163
// Basic properties check
164-
test.equal(1, result.nInserted);
164+
test.equal(1, result.insertedCount);
165165
test.equal(true, result.hasWriteErrors());
166166
test.equal(1, result.getWriteErrorCount());
167167

@@ -322,7 +322,7 @@ describe('Bulk', function () {
322322
// Basic properties check
323323
result = err.result;
324324
test.equal(err instanceof Error, true);
325-
test.equal(1, result.nInserted);
325+
test.equal(1, result.insertedCount);
326326
test.equal(true, result.hasWriteErrors());
327327
test.ok(1, result.getWriteErrorCount());
328328

@@ -387,7 +387,7 @@ describe('Bulk', function () {
387387
// Execute the operations
388388
batch.execute(function (err, result) {
389389
// Basic properties check
390-
test.equal(6, result.nInserted);
390+
test.equal(6, result.insertedCount);
391391
test.equal(false, result.hasWriteErrors());
392392

393393
// Finish up test
@@ -412,10 +412,10 @@ describe('Bulk', function () {
412412

413413
// Test basic settings
414414
const result = thrownError.result;
415-
expect(result).to.have.property('nInserted', 1);
416-
expect(result).to.have.property('nMatched', 1);
415+
expect(result).to.have.property('insertedCount', 1);
416+
expect(result).to.have.property('matchedCount', 1);
417417
expect(result)
418-
.to.have.property('nModified')
418+
.to.have.property('modifiedCount')
419419
.that.satisfies(v => v == null || v === 1);
420420
expect(result).to.have.property('hasWriteErrors').that.is.a('function');
421421
expect(result).to.have.property('getWriteErrorCount').that.is.a('function');
@@ -455,10 +455,10 @@ describe('Bulk', function () {
455455

456456
// Test basic settings
457457
const result = originalError.result;
458-
test.equal(1, result.nInserted);
459-
test.equal(2, result.nUpserted);
460-
test.equal(1, result.nMatched);
461-
test.ok(1 === result.nModified || result.nModified == null);
458+
test.equal(1, result.insertedCount);
459+
test.equal(2, result.upsertedCount);
460+
test.equal(1, result.matchedCount);
461+
test.ok(1 === result.modifiedCount || result.modifiedCount == null);
462462
test.equal(true, result.hasWriteErrors());
463463
test.equal(1, result.getWriteErrorCount());
464464

@@ -470,7 +470,7 @@ describe('Bulk', function () {
470470
test.equal(1, error.getOperation().b);
471471

472472
// Check for upserted values
473-
const ids = result.getUpsertedIds();
473+
const ids = result.result.upserted;
474474
test.equal(2, ids.length);
475475
test.equal(2, ids[0].index);
476476
test.ok(ids[0]._id != null);
@@ -498,13 +498,13 @@ describe('Bulk', function () {
498498
// Execute the operations
499499
batch.execute(function (err, result) {
500500
// Check state of result
501-
test.equal(1, result.nUpserted);
502-
test.equal(0, result.nInserted);
503-
test.equal(0, result.nMatched);
504-
test.ok(0 === result.nModified || result.nModified == null);
505-
test.equal(0, result.nRemoved);
501+
test.equal(1, result.upsertedCount);
502+
test.equal(0, result.insertedCount);
503+
test.equal(0, result.matchedCount);
504+
test.ok(0 === result.modifiedCount || result.modifiedCount == null);
505+
test.equal(0, result.deletedCount);
506506

507-
const upserts = result.getUpsertedIds();
507+
const upserts = result.result.upserted;
508508
test.equal(1, upserts.length);
509509
test.equal(0, upserts[0].index);
510510
test.equal(2, upserts[0]._id);
@@ -551,11 +551,11 @@ describe('Bulk', function () {
551551

552552
bulk.execute({ writeConcern: { w: 0 } }, function (err, result) {
553553
expect(err).to.not.exist;
554-
test.equal(0, result.nUpserted);
555-
test.equal(0, result.nInserted);
556-
test.equal(0, result.nMatched);
557-
test.ok(0 === result.nModified || result.nModified == null);
558-
test.equal(0, result.nRemoved);
554+
test.equal(0, result.upsertedCount);
555+
test.equal(0, result.insertedCount);
556+
test.equal(0, result.matchedCount);
557+
test.ok(0 === result.modifiedCount || result.modifiedCount == null);
558+
test.equal(0, result.deletedCount);
559559
test.equal(false, result.hasWriteErrors());
560560

561561
client.close(done);
@@ -591,10 +591,10 @@ describe('Bulk', function () {
591591
// Basic properties check
592592
result = err.result;
593593
test.equal(err instanceof Error, true);
594-
test.equal(2, result.nInserted);
595-
test.equal(0, result.nUpserted);
596-
test.equal(0, result.nMatched);
597-
test.ok(0 === result.nModified || result.nModified == null);
594+
test.equal(2, result.insertedCount);
595+
test.equal(0, result.upsertedCount);
596+
test.equal(0, result.matchedCount);
597+
test.ok(0 === result.modifiedCount || result.modifiedCount == null);
598598
test.equal(true, result.hasWriteErrors());
599599
test.equal(1, result.getWriteErrorCount());
600600

@@ -644,7 +644,7 @@ describe('Bulk', function () {
644644

645645
// Basic properties check
646646
result = err.result;
647-
expect(result.nInserted).to.equal(1);
647+
expect(result.insertedCount).to.equal(1);
648648
expect(result.hasWriteErrors()).to.equal(true);
649649
expect(result.getWriteErrorCount()).to.equal(1);
650650

@@ -718,7 +718,7 @@ describe('Bulk', function () {
718718
// Execute the operations
719719
batch.execute(function (err, result) {
720720
// Basic properties check
721-
test.equal(6, result.nInserted);
721+
test.equal(6, result.insertedCount);
722722
test.equal(false, result.hasWriteErrors());
723723

724724
// Finish up test
@@ -760,7 +760,7 @@ describe('Bulk', function () {
760760

761761
// Test basic settings
762762
result = err.result;
763-
test.equal(2, result.nInserted);
763+
test.equal(2, result.insertedCount);
764764
test.equal(true, result.hasWriteErrors());
765765
test.ok(result.getWriteErrorCount() === 4 || result.getWriteErrorCount() === 3);
766766

@@ -808,7 +808,7 @@ describe('Bulk', function () {
808808

809809
// Test basic settings
810810
result = err.result;
811-
expect(result.nInserted).to.equal(1);
811+
expect(result.insertedCount).to.equal(1);
812812
expect(result.hasWriteErrors()).to.equal(true);
813813
expect(result.getWriteErrorCount() === 1).to.equal(true);
814814

@@ -863,10 +863,10 @@ describe('Bulk', function () {
863863

864864
// Test basic settings
865865
result = err.result;
866-
test.equal(2, result.nInserted);
867-
test.equal(2, result.nUpserted);
868-
test.ok(0 === result.nModified || result.nModified == null);
869-
test.equal(0, result.nRemoved);
866+
test.equal(2, result.insertedCount);
867+
test.equal(2, result.upsertedCount);
868+
test.ok(0 === result.modifiedCount || result.modifiedCount == null);
869+
test.equal(0, result.deletedCount);
870870
test.equal(true, result.hasWriteErrors());
871871
test.ok(1, result.getWriteErrorCount());
872872

@@ -877,7 +877,7 @@ describe('Bulk', function () {
877877
test.equal(1, error.getOperation().u['$set'].b);
878878

879879
// Check for upserted values
880-
const ids = result.getUpsertedIds();
880+
const ids = result.result.upserted;
881881
test.equal(2, ids.length);
882882
test.equal(2, ids[0].index);
883883
test.ok(ids[0]._id != null);
@@ -907,13 +907,13 @@ describe('Bulk', function () {
907907
// Execute the operations
908908
batch.execute({}, function (err, result) {
909909
// Check state of result
910-
test.equal(1, result.nUpserted);
911-
test.equal(0, result.nInserted);
912-
test.equal(0, result.nMatched);
913-
test.ok(0 === result.nModified || result.nModified == null);
914-
test.equal(0, result.nRemoved);
910+
test.equal(1, result.upsertedCount);
911+
test.equal(0, result.insertedCount);
912+
test.equal(0, result.matchedCount);
913+
test.ok(0 === result.modifiedCount || result.modifiedCount == null);
914+
test.equal(0, result.deletedCount);
915915

916-
const upserts = result.getUpsertedIds();
916+
const upserts = result.result.upserted;
917917
test.equal(1, upserts.length);
918918
test.equal(0, upserts[0].index);
919919
test.equal(2, upserts[0]._id);
@@ -991,11 +991,11 @@ describe('Bulk', function () {
991991

992992
bulk.execute({ writeConcern: { w: 0 } }, function (err, result) {
993993
expect(err).to.not.exist;
994-
test.equal(0, result.nUpserted);
995-
test.equal(0, result.nInserted);
996-
test.equal(0, result.nMatched);
997-
test.ok(0 === result.nModified || result.nModified == null);
998-
test.equal(0, result.nRemoved);
994+
test.equal(0, result.upsertedCount);
995+
test.equal(0, result.insertedCount);
996+
test.equal(0, result.matchedCount);
997+
test.ok(0 === result.modifiedCount || result.modifiedCount == null);
998+
test.equal(0, result.deletedCount);
999999
test.equal(false, result.hasWriteErrors());
10001000

10011001
client.close(done);

test/integration/crud/crud_api.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ describe('CRUD API', function () {
342342
{ ordered: false, writeConcern: { w: 1 } },
343343
function (err, r) {
344344
expect(err).to.not.exist;
345-
test.equal(3, r.nInserted);
346-
test.equal(1, r.nUpserted);
347-
test.equal(1, r.nRemoved);
345+
test.equal(3, r.insertedCount);
346+
test.equal(1, r.upsertedCount);
347+
test.equal(1, r.deletedCount);
348348

349349
// Crud fields
350350
test.equal(3, r.insertedCount);
@@ -384,9 +384,9 @@ describe('CRUD API', function () {
384384
{ ordered: false, writeConcern: { w: 1 } },
385385
function (err, r) {
386386
expect(err).to.not.exist;
387-
test.equal(1, r.nInserted);
388-
test.equal(2, r.nUpserted);
389-
test.equal(2, r.nRemoved);
387+
test.equal(1, r.insertedCount);
388+
test.equal(2, r.upsertedCount);
389+
test.equal(2, r.deletedCount);
390390

391391
// Crud fields
392392
test.equal(1, r.insertedCount);
@@ -425,9 +425,9 @@ describe('CRUD API', function () {
425425
{ ordered: true, writeConcern: { w: 1 } },
426426
function (err, r) {
427427
expect(err).to.not.exist;
428-
test.equal(3, r.nInserted);
429-
test.equal(1, r.nUpserted);
430-
test.equal(1, r.nRemoved);
428+
test.equal(3, r.insertedCount);
429+
test.equal(1, r.upsertedCount);
430+
test.equal(1, r.deletedCount);
431431

432432
// Crud fields
433433
test.equal(3, r.insertedCount);
@@ -463,9 +463,9 @@ describe('CRUD API', function () {
463463
{ ordered: true, writeConcern: { w: 1 } },
464464
function (err, r) {
465465
// expect(err).to.not.exist;
466-
test.equal(1, r.nInserted);
467-
test.equal(2, r.nUpserted);
468-
test.equal(1, r.nRemoved);
466+
test.equal(1, r.insertedCount);
467+
test.equal(2, r.upsertedCount);
468+
test.equal(1, r.deletedCount);
469469

470470
// Crud fields
471471
test.equal(1, r.insertedCount);

test/integration/node-specific/operation_examples.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3776,15 +3776,15 @@ describe('Operations', function () {
37763776
// Execute the operations
37773777
return batch.execute().then(function (result) {
37783778
// Check state of result
3779-
expect(result.nInserted).to.equal(2);
3780-
expect(result.nUpserted).to.equal(1);
3781-
expect(result.nMatched).to.equal(1);
3779+
expect(result.insertedCount).to.equal(2);
3780+
expect(result.upsertedCount).to.equal(1);
3781+
expect(result.matchedCount).to.equal(1);
37823782
expect(
3783-
1 === result.nModified || result.nModified === 0 || result.nModified == null
3783+
1 === result.modifiedCount || result.modifiedCount === 0 || result.modifiedCount == null
37843784
).to.exist;
3785-
expect(result.nRemoved).to.equal(1);
3785+
expect(result.deletedCount).to.equal(1);
37863786

3787-
const upserts = result.getUpsertedIds();
3787+
const upserts = result.result.upserted;
37883788
expect(upserts.length).to.equal(1);
37893789
expect(upserts[0].index).to.equal(2);
37903790
expect(upserts[0]._id != null).to.exist;
@@ -3845,15 +3845,15 @@ describe('Operations', function () {
38453845
// Execute the operations
38463846
return batch.execute().then(function (result) {
38473847
// Check state of result
3848-
expect(result.nInserted).to.equal(2);
3849-
expect(result.nUpserted).to.equal(1);
3850-
expect(result.nMatched).to.equal(1);
3848+
expect(result.insertedCount).to.equal(2);
3849+
expect(result.upsertedCount).to.equal(1);
3850+
expect(result.matchedCount).to.equal(1);
38513851
expect(
3852-
1 === result.nModified || result.nModified === 0 || result.nModified == null
3852+
1 === result.modifiedCount || result.modifiedCount === 0 || result.modifiedCount == null
38533853
).to.exist;
3854-
expect(result.nRemoved).to.equal(1);
3854+
expect(result.deletedCount).to.equal(1);
38553855

3856-
const upserts = result.getUpsertedIds();
3856+
const upserts = result.result.upserted;
38573857
expect(upserts.length).to.equal(1);
38583858
expect(upserts[0].index).to.equal(2);
38593859
expect(upserts[0]._id != null).to.exist;
@@ -4169,9 +4169,9 @@ describe('Operations', function () {
41694169
{ ordered: true, writeConcern: { w: 1 } }
41704170
)
41714171
.then(function (r) {
4172-
expect(r.nInserted).to.equal(1);
4173-
expect(r.nUpserted).to.equal(2);
4174-
expect(r.nRemoved).to.equal(0);
4172+
expect(r.insertedCount).to.equal(1);
4173+
expect(r.upsertedCount).to.equal(2);
4174+
expect(r.deletedCount).to.equal(0);
41754175
// Crud fields
41764176
expect(r.insertedCount).to.equal(1);
41774177
expect(Object.keys(r.insertedIds).length).to.equal(1);

0 commit comments

Comments
 (0)