continue work on user migration

This commit is contained in:
Michael Q Larson
2015-04-13 01:03:26 -04:00
parent e98f445444
commit 83c14cccc4
2 changed files with 32 additions and 24 deletions

View File

@ -65,7 +65,7 @@ var userSchema = new mongoose.Schema({
default: ''
}
},
challengesHash: {},
portfolio: {
website1Link: {
type: String,
@ -137,7 +137,8 @@ var userSchema = new mongoose.Schema({
longestStreak: {
type: Number,
default: 0
}
},
needsMigration: { type: Boolean, default: true }
});
/**

View File

@ -10,26 +10,33 @@ var mongoClient = new MongoClient(new Server('localhost', 27017), {native_parser
var mongoose = require('mongoose');
mongoose.connect(secrets.db);
User.find(function(err, users) {
if (err) { console.log(err) }
users.forEach(function(user) {
console.log('in users');
if (typeof user.challengesHash !== 'undefined') {
var oldChallenges = Object.keys(user.challengesHash).filter(function (challenge) {
return user.challengesHash[challenge];
}).map(function (data) {
return ({
challengeNum: data,
timeStamp: user.challengesHash[data]
});
});
oldChallenges.forEach(function (challenge) {
user.progressTimestamps.push(challenge.timeStamp);
});
newChallenges = newChallenges.filter(function (elem) {
return elem.newId;
});
console.log(newChallenges);
}
});
var stream = User.find( { needsMigration: true }).batchSize(10000).stream();
stream.on('data', function(user) {
console.log('test');
user.needsMigration = true;
user.save();
}).on('error', function(err) {
console.log(err);
}).on('close', function() {
console.log('done with set');
});
//console.log(typeof(user.challengesHash));
//if (user.challengesHash && typeof(user.challengesHash) === Object) {
// var oldChallenges = Object.keys(user.challengesHash).filter(function (challenge) {
// console.log(challenge);
// return user.challengesHash[challenge];
// }).map(function (data) {
// return ({
// challengeNum: data,
// timeStamp: user.challengesHash[data]
// });
// });
// oldChallenges.forEach(function (challenge) {
// user.progressTimestamps.push(challenge.timeStamp);
// });
// newChallenges = newChallenges.filter(function (elem) {
// return elem.newId;
// });
// console.log(newChallenges);
//});
//});