2
0
Эх сурвалжийг харах

create dropindex TryCatch

Shun Miyazawa 3 жил өмнө
parent
commit
b6ab15a3a2

+ 9 - 2
packages/app/src/server/service/activity.ts

@@ -59,12 +59,19 @@ class ActivityService {
     const collection = mongoose.connection.collection('activities');
     const collection = mongoose.connection.collection('activities');
 
 
     try {
     try {
+      const targetField = 'createdAt_1';
       const indexes = await collection.getIndexes();
       const indexes = await collection.getIndexes();
-      const isExistTargetField = Object.keys(indexes).includes('createdAt_1');
+      const isExistTargetField = Object.keys(indexes).includes(targetField);
       if (isExistTargetField) {
       if (isExistTargetField) {
-        await collection.dropIndex('createdAt_1');
+        await collection.dropIndex(targetField);
       }
       }
+    }
+    catch (err) {
+      logger.error('Failed to drop target index', err);
+      return;
+    }
 
 
+    try {
       // Set retention period only if activityExpirationSeconds is not null
       // Set retention period only if activityExpirationSeconds is not null
       await collection.createIndex({ createdAt: 1 }, { expireAfterSeconds: activityExpirationSeconds });
       await collection.createIndex({ createdAt: 1 }, { expireAfterSeconds: activityExpirationSeconds });
     }
     }