|
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'; |
9 | 2 | import type { Collection } from '../collection';
|
10 | 3 | import {
|
11 | 4 | AnyError,
|
@@ -146,7 +139,6 @@ export interface BulkResult {
|
146 | 139 | nModified: number;
|
147 | 140 | nRemoved: number;
|
148 | 141 | upserted: Document[];
|
149 |
| - opTime?: Document; |
150 | 142 | }
|
151 | 143 |
|
152 | 144 | /**
|
@@ -300,15 +292,6 @@ export class BulkWriteResult {
|
300 | 292 | return this.result.writeErrors;
|
301 | 293 | }
|
302 | 294 |
|
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 |
| - |
312 | 295 | /** Retrieve the write concern error if one exists */
|
313 | 296 | getWriteConcernError(): WriteConcernError | undefined {
|
314 | 297 | if (this.result.writeConcernErrors.length === 0) {
|
@@ -449,12 +432,6 @@ export class WriteError {
|
449 | 432 | }
|
450 | 433 | }
|
451 | 434 |
|
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 |
| - |
458 | 435 | /** Merges results into shared data structure */
|
459 | 436 | export function mergeBatchResults(
|
460 | 437 | batch: Batch,
|
@@ -491,44 +468,6 @@ export function mergeBatchResults(
|
491 | 468 | return;
|
492 | 469 | }
|
493 | 470 |
|
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 |
| - |
532 | 471 | // If we have an insert Batch type
|
533 | 472 | if (isInsertBatch(batch) && result.n) {
|
534 | 473 | bulkResult.nInserted = bulkResult.nInserted + result.n;
|
|
0 commit comments