Selaa lähdekoodia

Add script that fixes translation format in db

Tati 9 vuotta sitten
vanhempi
commit
19f3ab06bb
1 muutettua tiedostoa jossa 30 lisäystä ja 0 poistoa
  1. 30 0
      back/fix-translation-format.script.js

+ 30 - 0
back/fix-translation-format.script.js

@@ -0,0 +1,30 @@
+var conn = new Mongo();
+var db = conn.getDB('eba');
+var products = db.products.find();
+
+function mkNewFormat(p) {
+    return {
+        _id: p._id,
+        name: p.name,
+        imgUrl: p.imgUrl,
+        thumbUrl: p.thumbUrl,
+        size: p.size,
+        ES: {
+            text: p.description.text.ES,
+            category: {
+                _id: p.category._id,
+                name: p.category.name.ES
+            }
+        }, 
+        EN: {
+            category: {
+                _id: p.category._id,
+                name: p.category.name.EN
+            }
+        }
+    }
+}
+
+products.forEach(function (p) {
+    db.products.update({_id: p._id}, mkNewFormat(p))
+})