var conn = new Mongo(); var db = conn.getDB('eba'); var categories = db.categories.find(); var oldProducts = db.productos.find(); var newCategoriesFormat = { '1': { "_id" : ObjectId( "58caba2ce53f0644597b74e3" ), "name" : { "EN" : "cleansers", "ES" : "higiene" } }, '2': { "_id" : ObjectId( "58caba2ce53f0644597b74e4" ), "name" : { "EN" : "masks", "ES" : "mascaras" } }, '3': { "_id" : ObjectId( "58caba2ce53f0644597b74ec" ), "name" : { "EN" : "hyaluronic acid", "ES" : "acido hialuronico" } }, '4': { "_id" : ObjectId( "58caba2ce53f0644597b74e5" ), "name" : { "EN" : "peeling", "ES" : "peels" } }, '5': { "_id" : ObjectId( "58caba2ce53f0644597b74e6" ), "name" : { "EN" : "body", "ES" : "corporales" } }, '6': { "_id" : ObjectId( "58caba2ce53f0644597b74e7" ), "name" : { "EN" : "men", "ES" : "hombres" } }, '7': { "_id" : ObjectId( "58caba2ce53f0644597b74e8" ), "name" : { "EN" : "intensive treatment", "ES" : "proteccion intensiva" } }, '8': { "_id" : ObjectId( "58caba2ce53f0644597b74eb" ), "name" : { "EN" : "ampoules", "ES" : "monodosis" } }, '9': { "_id" : ObjectId( "58caba2ce53f0644597b74e9" ), "name" : { "EN" : "concentrated actives", "ES" : "activos concentrados" } }, '10': { "_id" : ObjectId( "58caba2ce53f0644597b74ea" ), "name" : { "EN" : "sun protection", "ES" : "protectores solares" } } }; function mkSize(s) { return s.replace(/\./g, '').split(' | '); } function mkProduct(p) { return { name: p.nombre, category: newCategoriesFormat[p.categoria], imgUrl: p.imagen, thumbUrl: p.thumb, size: mkSize(p.presentacion) } } oldProducts.forEach(function (p) { var newp = mkProduct(p); printjson(newp); db.products.insert(newp); })