Explorar o código

use bulkWrite

utsushiiro %!s(int64=7) %!d(string=hai) anos
pai
achega
979f62f611
Modificáronse 1 ficheiros con 9 adicións e 9 borrados
  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) {
-    const results = [];
+    let queries = [];
     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();
   }