Meteor.methods({ // Cleans up all Date objects that don't have a time component. Removes any time component. "cleanDates": async function() { // Update the sales dates. let sales = await Sales.find({}).fetchAsync(); for(let i = 0; i < sales.length; i++) { if(sales[i].date && _.isDate(sales[i].date)) { let date = ~~(moment(sales[i].date).format("YYYYMMDD")); console.log("Converted " + sales[i].date + " to " + date); // Save to the database. await Sales.updateAsync(sales[i]._id, {$set: {date}}, function(err, id) { if(err) console.log(err); }, {bypassCollection2: true}); } } console.log("+++++++++++++++++++++++++++++++ FINISHED Sales +++++++++++++++++++++++++++++"); // Update the product price effective dates. let products = await Products.find({}).fetchAsync(); for(let i = 0; i < products.length; i++) { let product = products[i]; let hasChanges = false; let prices = product.prices; if(prices) { for(let prop in prices) { if(prices[prop] && prices[prop].effectiveDate) { if(_.isDate(prices[prop].effectiveDate)) { let oldDate = prices[prop].effectiveDate; prices[prop].effectiveDate = ~~(moment(prices[prop].effectiveDate).format("YYYYMMDD")); console.log("Converted " + oldDate + " to " + prices[prop].effectiveDate + " for the product " + product.name); hasChanges = true; } } } } // Save the changes. if(hasChanges) { await Products.updateAsync(product._id, {$set: {prices}}, function(err, id) { if(err) console.log(err); }, {validate: false, bypassCollection2: true}); } } } });