Skip to content

Commit 2ab77fb

Browse files
committed
fix: bulk
1 parent 3acfb6d commit 2ab77fb

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

src/bulk/common.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,38 +1276,41 @@ export abstract class BulkOperationBase {
12761276
: typeof options === 'function'
12771277
? options
12781278
: undefined;
1279+
options = options != null && typeof options !== 'function' ? options : {};
12791280

1280-
return maybeCallback(async () => {
1281-
options = options != null && typeof options !== 'function' ? options : {};
1282-
1283-
if (this.s.executed) {
1281+
if (this.s.executed) {
1282+
// eslint-disable-next-line @typescript-eslint/require-await
1283+
return maybeCallback(async () => {
12841284
throw new MongoBatchReExecutionError();
1285-
}
1285+
}, callback);
1286+
}
12861287

1287-
const writeConcern = WriteConcern.fromOptions(options);
1288-
if (writeConcern) {
1289-
this.s.writeConcern = writeConcern;
1290-
}
1288+
const writeConcern = WriteConcern.fromOptions(options);
1289+
if (writeConcern) {
1290+
this.s.writeConcern = writeConcern;
1291+
}
12911292

1292-
// If we have current batch
1293-
if (this.isOrdered) {
1294-
if (this.s.currentBatch) this.s.batches.push(this.s.currentBatch);
1295-
} else {
1296-
if (this.s.currentInsertBatch) this.s.batches.push(this.s.currentInsertBatch);
1297-
if (this.s.currentUpdateBatch) this.s.batches.push(this.s.currentUpdateBatch);
1298-
if (this.s.currentRemoveBatch) this.s.batches.push(this.s.currentRemoveBatch);
1299-
}
1300-
// If we have no operations in the bulk raise an error
1301-
if (this.s.batches.length === 0) {
1293+
// If we have current batch
1294+
if (this.isOrdered) {
1295+
if (this.s.currentBatch) this.s.batches.push(this.s.currentBatch);
1296+
} else {
1297+
if (this.s.currentInsertBatch) this.s.batches.push(this.s.currentInsertBatch);
1298+
if (this.s.currentUpdateBatch) this.s.batches.push(this.s.currentUpdateBatch);
1299+
if (this.s.currentRemoveBatch) this.s.batches.push(this.s.currentRemoveBatch);
1300+
}
1301+
// If we have no operations in the bulk raise an error
1302+
if (this.s.batches.length === 0) {
1303+
// eslint-disable-next-line @typescript-eslint/require-await
1304+
return maybeCallback(async () => {
13021305
throw new MongoInvalidArgumentError('Invalid BulkOperation, Batch cannot be empty');
1303-
}
1306+
}, callback);
1307+
}
13041308

1305-
this.s.executed = true;
1306-
const finalOptions = { ...this.s.options, ...options };
1307-
const operation = new BulkWriteShimOperation(this, finalOptions);
1309+
this.s.executed = true;
1310+
const finalOptions = { ...this.s.options, ...options };
1311+
const operation = new BulkWriteShimOperation(this, finalOptions);
13081312

1309-
return await executeOperation(this.s.collection.s.db.s.client, operation);
1310-
}, callback);
1313+
return executeOperation(this.s.collection.s.db.s.client, operation, callback);
13111314
}
13121315

13131316
/**

test/integration/sessions/sessions.spec.prose.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ describe('ServerSession', () => {
4646
expect(events).to.have.lengthOf(operations.length);
4747

4848
// This is a guarantee in node, unless you are performing a transaction (which is not being done in this test)
49-
expect(new Set(events.map(ev => ev.command.lsid.id.toString('hex'))).size).to.equal(1);
49+
expect(new Set(events.map(ev => ev.command.lsid.id.toString('hex')))).to.have.lengthOf(1);
5050
});
5151
});

0 commit comments

Comments
 (0)