Replace insertMany operation with upsert for backfilling trusted ips

This commit is contained in:
Tuan Dang
2023-07-26 20:45:58 +07:00
parent 511904605f
commit 8dbc894ce9
+22 -11
View File
@@ -568,18 +568,29 @@ export const backfillTrustedIps = async () => {
} }
}); });
if (workspaceIdsToAddTrustedIp.length === 0) return; if (workspaceIdsToAddTrustedIp.length > 0) {
const operations = workspaceIdsToAddTrustedIp.map((workspaceId) => {
const update = {
workspace: workspaceId,
ipAddress: "0.0.0.0",
type: IPType.IPV4,
prefix: 0,
isActive: true,
comment: ""
}
const trustedIpsToInsert = workspaceIdsToAddTrustedIp.map((workspaceId) => { return {
return new TrustedIP({ updateOne: {
workspace: workspaceId, filter: update,
ipAddress: "0.0.0.0", update: {
type: IPType.IPV4, $setOnInsert: update
prefix: 0, },
isActive: true, upsert: true,
comment: "", },
};
}); });
});
await TrustedIP.insertMany(trustedIpsToInsert); await TrustedIP.bulkWrite(operations);
console.log("Backfill: Trusted IPs complete");
}
} }