Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 88c2186

Browse files
authored
DOP-3754: skip bulk upsert if operations empty (#830)
skip bulk upsert if operations empty
1 parent 5a6396b commit 88c2186

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

modules/persistence/src/services/connector/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export const insert = async (docs: any[], collection: string, buildId: ObjectId)
5858
export const bulkWrite = async (operations: mongodb.AnyBulkWriteOperation[], collection: string) => {
5959
const dbSession = await db();
6060
try {
61+
if (!operations || !operations.length) {
62+
return;
63+
}
6164
return dbSession.collection(collection).bulkWrite(operations, { ordered: false });
6265
} catch (error) {
6366
console.error(`Error at bulk write time for ${collection}: ${error}`);

modules/persistence/tests/services/connector.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,11 @@ describe('Connector module', () => {
147147
expect(e.message).toEqual('test error');
148148
}
149149
});
150+
151+
test('it skips bulkwrite if operations are empty', async () => {
152+
mockBulkWrite.mockReset();
153+
await bulkUpsertAll([], collection);
154+
expect(mockBulkWrite).toBeCalledTimes(0);
155+
});
150156
});
151157
});

0 commit comments

Comments
 (0)