Last active
August 29, 2015 14:06
-
-
Save Quentin01/4dd03a8fed038b26b1e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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