forked from HabitRPG/habitica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20140823_remove_undefined_and_false_notifications.js
45 lines (34 loc) · 1.58 KB
/
20140823_remove_undefined_and_false_notifications.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// node .migrations/20140823_remove_undefined_and_false_notifications.js
var migrationName = '20140823_remove_undefined_and_false_notifications';
var authorName = 'Alys'; // in case script author needs to know when their ...
var authorUuid = 'd904bd62-da08-416b-a816-ba797c9ee265'; //... own data is done
/**
* https://github.com/HabitRPG/habitrpg/pull/3907
*/
var mongo = require('mongoskin');
var _ = require('lodash');
// XXX @lefnire, choose wisely:
// var liveUsers = mongo.db('lefnire:[email protected]:10015/habitrpg_large?auto_reconnect').collection('users');
// var liveUsers = mongo.db('localhost:27017/habitrpg_old?auto_reconnect').collection('users');
// For local testing by script author:
// var liveUsers = mongo.db('localhost:27017/habitrpg?auto_reconnect').collection('users');
var fields = {migration:1,newMessages:1};
var progressCount = 1000;
// var progressCount = 1;
var count = 0;
liveUsers.findEach({migration: {$ne:migrationName}}, fields, {batchSize:250}, function(err, user){
count++;
if (!user) err = '!user';
if (err) {return console.error(err);}
var newNewMessages = {};
_.each(user.newMessages,function(val,key){
// console.log(key + " " + val.name);
if(key != "undefined" && val['value']){
newNewMessages[key] = val;
}
})
liveUsers.update({_id:user._id}, {$set:{newMessages:newNewMessages, migration:migrationName}, $inc:{_v:1}});
if (count%progressCount == 0) console.log(count + ' ' + user._id);
if (user._id == '9') console.log('lefnire processed');
if (user._id == authorUuid) console.log(authorName + ' processed');
});