From 7589627dae2b98f89d6a1fa0b92257179aa60740 Mon Sep 17 00:00:00 2001 From: Alan Le Ruyet Date: Wed, 18 Dec 2024 10:57:58 +0100 Subject: [PATCH] feat: migration --- .../20241218094540-fix-recruiter-missing-geopoint.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 server/src/migrations/20241218094540-fix-recruiter-missing-geopoint.ts diff --git a/server/src/migrations/20241218094540-fix-recruiter-missing-geopoint.ts b/server/src/migrations/20241218094540-fix-recruiter-missing-geopoint.ts new file mode 100755 index 000000000..f30482012 --- /dev/null +++ b/server/src/migrations/20241218094540-fix-recruiter-missing-geopoint.ts @@ -0,0 +1,11 @@ +import { logger } from "@/common/logger" +import { getDbCollection } from "@/common/utils/mongodbUtils" + +export const up = async () => { + logger.info("20241218-fix-recruiter-missing-geopoint started") + for await (const { _id, geo_coordinates } of getDbCollection("recruiters").find({ geopoint: null, geo_coordinates: { $ne: null } })) { + const [latitude, longitude] = geo_coordinates!.split(",").map((coord) => parseFloat(coord)) + await getDbCollection("recruiters").updateOne({ _id }, { $set: { geopoint: { type: "Point", coordinates: [longitude, latitude] } } }) + } + logger.info("20241218-fix-recruiter-missing-geopoint ended") +}