Browse Source

use bulkWrite

utsushiiro 7 years ago
parent
commit
979f62f611
1 changed files with 9 additions and 9 deletions
  1. 9 9
      src/server/service/config-manager.js

+ 9 - 9
src/server/service/config-manager.js

@@ -87,17 +87,17 @@ class ConfigManager {
    * ```
    * ```
    */
    */
   async updateConfigsInTheSameNamespace(namespace, configs) {
   async updateConfigsInTheSameNamespace(namespace, configs) {
-    const results = [];
+    let queries = [];
     for (const key of Object.keys(configs)) {
     for (const key of Object.keys(configs)) {
-      results.push(
-        this.configModel.findOneAndUpdate(
-          { ns: namespace, key: key },
-          { ns: namespace, key: key, value: this.convertInsertValue(configs[key]) },
-          { upsert: true, }
-        ).exec()
-      );
+      queries.push({
+        updateOne: {
+          filter: { ns: namespace, key: key },
+          update: { ns: namespace, key: key, value: this.convertInsertValue(configs[key]) },
+          upsert: true
+        }
+      });
     }
     }
-    await Promise.all(results);
+    await this.configModel.bulkWrite(queries);
 
 
     await this.loadConfigs();
     await this.loadConfigs();
   }
   }