Skip to content

Commit 8900d40

Browse files
authored
feat(NODE-3695)!: remove lastop and optime from bulk result (#3504)
1 parent 88c03a1 commit 8900d40

File tree

3 files changed

+6
-194
lines changed

3 files changed

+6
-194
lines changed

etc/notes/CHANGES_5.0.0.md

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ The following is a detailed collection of the changes in the major v5 release of
1616

1717
## Changes
1818

19+
### Bulk results no longer contain `lastOp()` and `opTime`
20+
21+
The `lastOp()` method and `opTime` property on the `BulkResult` have been removed. Merging of bulk results
22+
no longer normalizes the values. There is no new method or property to replace them.
23+
1924
### `CursorCloseOptions` removed
2025

2126
When calling `close()` on a `Cursor`, no more options can be provided. This removes support for the

src/bulk/common.ts

+1-62
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
BSONSerializeOptions,
3-
Document,
4-
Long,
5-
ObjectId,
6-
resolveBSONOptions,
7-
Timestamp
8-
} from '../bson';
1+
import { BSONSerializeOptions, Document, ObjectId, resolveBSONOptions } from '../bson';
92
import type { Collection } from '../collection';
103
import {
114
AnyError,
@@ -146,7 +139,6 @@ export interface BulkResult {
146139
nModified: number;
147140
nRemoved: number;
148141
upserted: Document[];
149-
opTime?: Document;
150142
}
151143

152144
/**
@@ -300,15 +292,6 @@ export class BulkWriteResult {
300292
return this.result.writeErrors;
301293
}
302294

303-
/**
304-
* Retrieve lastOp if available
305-
*
306-
* @deprecated Will be removed in 5.0
307-
*/
308-
getLastOp(): Document | undefined {
309-
return this.result.opTime;
310-
}
311-
312295
/** Retrieve the write concern error if one exists */
313296
getWriteConcernError(): WriteConcernError | undefined {
314297
if (this.result.writeConcernErrors.length === 0) {
@@ -449,12 +432,6 @@ export class WriteError {
449432
}
450433
}
451434

452-
/** Converts the number to a Long or returns it. */
453-
function longOrConvert(value: number | Long | Timestamp): Long | Timestamp {
454-
// TODO(NODE-2674): Preserve int64 sent from MongoDB
455-
return typeof value === 'number' ? Long.fromNumber(value) : value;
456-
}
457-
458435
/** Merges results into shared data structure */
459436
export function mergeBatchResults(
460437
batch: Batch,
@@ -491,44 +468,6 @@ export function mergeBatchResults(
491468
return;
492469
}
493470

494-
// The server write command specification states that lastOp is an optional
495-
// mongod only field that has a type of timestamp. Across various scarce specs
496-
// where opTime is mentioned, it is an "opaque" object that can have a "ts" and
497-
// "t" field with Timestamp and Long as their types respectively.
498-
// The "lastOp" field of the bulk write result is never mentioned in the driver
499-
// specifications or the bulk write spec, so we should probably just keep its
500-
// value consistent since it seems to vary.
501-
// See: https://github.com/mongodb/specifications/blob/master/source/driver-bulk-update.rst#results-object
502-
if (result.opTime || result.lastOp) {
503-
let opTime = result.lastOp || result.opTime;
504-
505-
// If the opTime is a Timestamp, convert it to a consistent format to be
506-
// able to compare easily. Converting to the object from a timestamp is
507-
// much more straightforward than the other direction.
508-
if (opTime._bsontype === 'Timestamp') {
509-
opTime = { ts: opTime, t: Long.ZERO };
510-
}
511-
512-
// If there's no lastOp, just set it.
513-
if (!bulkResult.opTime) {
514-
bulkResult.opTime = opTime;
515-
} else {
516-
// First compare the ts values and set if the opTimeTS value is greater.
517-
const lastOpTS = longOrConvert(bulkResult.opTime.ts);
518-
const opTimeTS = longOrConvert(opTime.ts);
519-
if (opTimeTS.greaterThan(lastOpTS)) {
520-
bulkResult.opTime = opTime;
521-
} else if (opTimeTS.equals(lastOpTS)) {
522-
// If the ts values are equal, then compare using the t values.
523-
const lastOpT = longOrConvert(bulkResult.opTime.t);
524-
const opTimeT = longOrConvert(opTime.t);
525-
if (opTimeT.greaterThan(lastOpT)) {
526-
bulkResult.opTime = opTime;
527-
}
528-
}
529-
}
530-
}
531-
532471
// If we have an insert Batch type
533472
if (isInsertBatch(batch) && result.n) {
534473
bulkResult.nInserted = bulkResult.nInserted + result.n;

test/unit/bulk/common.test.js

-132
This file was deleted.

0 commit comments

Comments
 (0)