oneuptime/init-script/scripts/3.0.5762.ts
Nawaz Dhandala afd62f21ce
fix lint
2022-03-22 14:33:55 +00:00

37 lines
1.1 KiB
TypeScript

import { find, update, removeField, rename } from '../util/db';
const monitorCategoryCollection = 'monitorcategories';
const resourceCategoryCollection = 'resourcecategories';
const monitorCollection = 'monitors';
async function run() {
// rename collection
await rename(monitorCategoryCollection, resourceCategoryCollection);
// get all monitors that have a monitorCategoryId
const monitors = await find(monitorCollection, {
monitorCategoryId: { $exists: true },
});
monitors.forEach(async (monitor: $TSFixMe) => {
const resourceCategory = monitor.monitorCategoryId;
// set their resourceCategory as the monitorCategoryId
await update(
monitorCollection,
{ _id: monitor._id },
{ resourceCategory }
);
// remove the monitorCategoryId field
await removeField(
monitorCollection,
{ _id: monitor._id },
'monitorCategoryId'
);
});
return `Script ran for ${monitors.length} monitors`;
}
export default run;