continue work on user migration
This commit is contained in:
@ -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 }
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
//});
|
||||
//});
|
||||
|
Reference in New Issue
Block a user