Shun Miyazawa 1 год назад
Родитель
Сommit
3f2e04995f

+ 10 - 14
apps/app/src/server/service/normalize-data/convert-revision-page-id-to-string.ts

@@ -8,21 +8,17 @@ import { type IRevisionModel } from '~/server/models/revision';
 export const convertRevisionPageIdToString = async(): Promise<void> => {
   const Revision = mongoose.model<IRevisionHasId, IRevisionModel>('Revision');
 
-  // Find pageId fields that are not of type string
-  const targetDocuments = await Revision.find({ $expr: { $not: { $eq: [{ $type: '$pageId' }, 'string'] } } });
-
-  const requests = targetDocuments.map((revision) => {
-    return {
-      updateOne: {
-        filter: { _id: revision._id },
-        update: {
-          $set: {
-            pageId: revision.pageId.toString(),
+  // Find and update pageId fields that are not of type string
+  await Revision.updateMany(
+    { $expr: { $not: { $eq: [{ $type: '$pageId' }, 'string'] } } },
+    [
+      {
+        $set: {
+          pageId: {
+            $toString: '$pageId',
           },
         },
       },
-    };
-  });
-
-  await Revision.bulkWrite(requests);
+    ],
+  );
 };