codecombat/scripts/mongodb/migrations/2016-09-16-fix-patch-originals.js

25 lines
834 B
JavaScript
Raw Normal View History

// Usage: Paste into mongodb client
VERSIONED_COLLECTIONS = {
'article': db.articles,
'level': db.levels,
'level_component': db.level.components,
'level_system': db.level.systems,
'thang_type': db.thang.types
};
db.patches.find({created:{$gt: '2016-09-08'}}).forEach(function(patch) {
if (!VERSIONED_COLLECTIONS[patch.target.collection]) {
print('skip', patch.target.collection);
return;
}
if (patch.target.original && patch.target.id && patch.target.original.equals(patch.target.id)) {
target = VERSIONED_COLLECTIONS[patch.target.collection].findOne({_id: patch.target.original});
print('found original', target, target._id, target.original);
db.patches.update({_id: patch._id}, {$set: {'target.original': target.original}});
}
else {
print('They are different, they are fine');
}
});