Skip to content

Commit dbad51e

Browse files
committed
fix: bulk
1 parent c084444 commit dbad51e

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
@@ -1266,38 +1266,41 @@ export abstract class BulkOperationBase {
12661266
: typeof options === 'function'
12671267
? options
12681268
: undefined;
1269+
options = options != null && typeof options !== 'function' ? options : {};
12691270

1270-
return maybeCallback(async () => {
1271-
options = options != null && typeof options !== 'function' ? options : {};
1272-
1273-
if (this.s.executed) {
1271+
if (this.s.executed) {
1272+
// eslint-disable-next-line @typescript-eslint/require-await
1273+
return maybeCallback(async () => {
12741274
throw new MongoBatchReExecutionError();
1275-
}
1275+
}, callback);
1276+
}
12761277

1277-
const writeConcern = WriteConcern.fromOptions(options);
1278-
if (writeConcern) {
1279-
this.s.writeConcern = writeConcern;
1280-
}
1278+
const writeConcern = WriteConcern.fromOptions(options);
1279+
if (writeConcern) {
1280+
this.s.writeConcern = writeConcern;
1281+
}
12811282

1282-
// If we have current batch
1283-
if (this.isOrdered) {
1284-
if (this.s.currentBatch) this.s.batches.push(this.s.currentBatch);
1285-
} else {
1286-
if (this.s.currentInsertBatch) this.s.batches.push(this.s.currentInsertBatch);
1287-
if (this.s.currentUpdateBatch) this.s.batches.push(this.s.currentUpdateBatch);
1288-
if (this.s.currentRemoveBatch) this.s.batches.push(this.s.currentRemoveBatch);
1289-
}
1290-
// If we have no operations in the bulk raise an error
1291-
if (this.s.batches.length === 0) {
1283+
// If we have current batch
1284+
if (this.isOrdered) {
1285+
if (this.s.currentBatch) this.s.batches.push(this.s.currentBatch);
1286+
} else {
1287+
if (this.s.currentInsertBatch) this.s.batches.push(this.s.currentInsertBatch);
1288+
if (this.s.currentUpdateBatch) this.s.batches.push(this.s.currentUpdateBatch);
1289+
if (this.s.currentRemoveBatch) this.s.batches.push(this.s.currentRemoveBatch);
1290+
}
1291+
// If we have no operations in the bulk raise an error
1292+
if (this.s.batches.length === 0) {
1293+
// eslint-disable-next-line @typescript-eslint/require-await
1294+
return maybeCallback(async () => {
12921295
throw new MongoInvalidArgumentError('Invalid BulkOperation, Batch cannot be empty');
1293-
}
1296+
}, callback);
1297+
}
12941298

1295-
this.s.executed = true;
1296-
const finalOptions = { ...this.s.options, ...options };
1297-
const operation = new BulkWriteShimOperation(this, finalOptions);
1299+
this.s.executed = true;
1300+
const finalOptions = { ...this.s.options, ...options };
1301+
const operation = new BulkWriteShimOperation(this, finalOptions);
12981302

1299-
return await executeOperation(this.s.collection.s.db.s.client, operation);
1300-
}, callback);
1303+
return executeOperation(this.s.collection.s.db.s.client, operation, callback);
13011304
}
13021305

13031306
/**

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)