Просмотр исходного кода

create the collection before creating ttl index

Yuki Takei 1 год назад
Родитель
Сommit
619e959f25
1 измененных файлов с 5 добавлено и 2 удалено
  1. 5 2
      apps/app/src/server/service/activity.ts

+ 5 - 2
apps/app/src/server/service/activity.ts

@@ -136,12 +136,15 @@ class ActivityService {
   createTtlIndex = async function() {
   createTtlIndex = async function() {
     const configManager = this.crowi.configManager;
     const configManager = this.crowi.configManager;
     const activityExpirationSeconds = configManager != null ? configManager.getConfig('crowi', 'app:activityExpirationSeconds') : 2592000;
     const activityExpirationSeconds = configManager != null ? configManager.getConfig('crowi', 'app:activityExpirationSeconds') : 2592000;
-    const collection = mongoose.connection.collection('activities');
 
 
     try {
     try {
-      const targetField = 'createdAt_1';
+      // create the collection with indexes at first
+      await Activity.createIndexes();
 
 
+      const collection = mongoose.connection.collection('activities');
       const indexes = await collection.indexes();
       const indexes = await collection.indexes();
+
+      const targetField = 'createdAt_1';
       const foundCreatedAt = indexes.find(i => i.name === targetField);
       const foundCreatedAt = indexes.find(i => i.name === targetField);
 
 
       const isNotSpec = foundCreatedAt?.expireAfterSeconds == null || foundCreatedAt?.expireAfterSeconds !== activityExpirationSeconds;
       const isNotSpec = foundCreatedAt?.expireAfterSeconds == null || foundCreatedAt?.expireAfterSeconds !== activityExpirationSeconds;