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
+24 -13
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 trustedIpsToInsert = workspaceIdsToAddTrustedIp.map((workspaceId) => { const update = {
return new TrustedIP({ workspace: workspaceId,
workspace: workspaceId, ipAddress: "0.0.0.0",
ipAddress: "0.0.0.0", type: IPType.IPV4,
type: IPType.IPV4, prefix: 0,
prefix: 0, isActive: true,
isActive: true, comment: ""
comment: "", }
});
});
await TrustedIP.insertMany(trustedIpsToInsert); return {
updateOne: {
filter: update,
update: {
$setOnInsert: update
},
upsert: true,
},
};
});
await TrustedIP.bulkWrite(operations);
console.log("Backfill: Trusted IPs complete");
}
} }