-
Notifications
You must be signed in to change notification settings - Fork 0
/
a.js
31 lines (27 loc) · 813 Bytes
/
a.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
var mongo = require('./lib/mongo');
var logger = require("./lib/log").getLogger('data-rebuild-schedule');
var appConf = require('./etc').application;
logger.debug("Beginning rebuild data...");
mongo.remove('user-days', {}, function (err, r) {
if (err) {
logger.error("Clear data error: %s", err);
} else {
mongo.find('users', {}, {}, function (err, ur) {
if (err) {
logger.error("Rebuild data error: %s", err);
} else {
var newData = [];
ur.forEach(function (user) {
newData.push({ "name": user.name, "available": [], "cars": [], "version": 1});
});
mongo.save('user-days', newData, function (err, sr) {
if (err) {
logger.error("Saving new data error: %s", err);
} else {
logger.debug("Saved new data successfully.");
}
});
}
});
}
});