/** * 一次性清理:删除 organization 集合里医院相关的记录。 * * 医院基础信息已统一迁移到 hospital 集合(schema/hospital.js), * organization 集合不再维护医院数据;本脚本删除 type=hospital 的记录。 * * 用法:在 api/health 下执行 `node scripts/delete_organization_hospitals.js` */ import { DBModel } from "../models/index.js"; DBModel.init(); const conn = DBModel.dbConnection; async function cleanup() { // 非医院记录(历史数据里可能有未填 type 的)统一保留,只删明确标记为医院的 const filter = { type: "hospital" }; const matched = await DBModel.Organization.countDocuments(filter).exec(); const result = await DBModel.Organization.deleteMany(filter); console.log(`deleted: matched=${matched}, deletedCount=${result.deletedCount}`); const remaining = await DBModel.Organization.countDocuments({}).exec(); console.log(`remaining organizations: ${remaining}`); await conn.close(); } if (conn.readyState === 1) { cleanup().catch((error) => { console.error(error); process.exit(1); }); } else { conn.once("connected", () => { cleanup().catch((error) => { console.error(error); process.exit(1); }); }); conn.once("error", (error) => { console.error(error); process.exit(1); }); }