Skip to content

Instantly share code, notes, and snippets.

@Quentin01
Last active August 29, 2015 14:06
Show Gist options
  • Save Quentin01/4dd03a8fed038b26b1e0 to your computer and use it in GitHub Desktop.
Save Quentin01/4dd03a8fed038b26b1e0 to your computer and use it in GitHub Desktop.
'use strict';
require('./app.js');
var async = require('async');
var mongoose = require('mongoose');
var Company = mongoose.model('Company');
Company.find().exec(function(err, companies) {
if (err) {
console.log(err);
process.exit(1);
}
async.each(companies, function(company, cb) {
if (company.hydraters.length === 0) {
return cb(null);
}
var hydraters = [];
company.hydraters.forEach(function(hydrater) {
hydraters.push(hydrater.replace(".hydrater.anyfetch.com/hydrate", ".anyfetch.com/hydrate"));
});
if (hydraters.toString() !== company.hydraters.toString()) {
company.hydraters = hydraters;
company.markModified('hydraters');
console.log("UPDATE", company.name);
console.log(company.hydraters);
company.save(cb);
}
else {
cb(null);
}
}, function(err) {
if (err) {
console.log(err);
process.exit(1);
}
mongoose.disconnect();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment