habitica/migrations/archive/2013/20130307_remove_duff_histories.js

28 lines
635 B
JavaScript
Raw Permalink Normal View History

/**
* Remove duff histories for dailies
*/
// mongo habitrpg ./node_modules/underscore/underscore.js ./migrations/20130307_remove_duff_histories.js
db.users.find().forEach(function (user) {
_.each(user.tasks, function (task, key) {
if (task.type === 'daily') {
// remove busted history entries
task.history = _.filter(task.history, function (h) {
return Boolean(h.value);
});
}
});
try {
db.users.update(
{_id: user._id},
{$set:
{
tasks: user.tasks,
},
},
{multi: true}
);
} catch (e) {
print(e);
}
});