use lean and .update

This commit is contained in:
Matteo Pagliazzi 2018-11-09 13:10:55 +01:00
parent 808885425f
commit ce03f837c7

View file

@ -8,23 +8,25 @@ let count = 0;
async function updateUser (user) {
count++;
user.migration = MIGRATION_NAME;
const set = {};
set.migration = MIGRATION_NAME;
if (user.items.pets['Bear-Veteran']) {
user.items.pets['Fox-Veteran'] = 5;
set['items.pets.Fox-Veteran'] = 5;
} else if (user.items.pets['Lion-Veteran']) {
user.items.pets['Bear-Veteran'] = 5;
set['items.pets.Bear-Veteran'] = 5;
} else if (user.items.pets['Tiger-Veteran']) {
user.items.pets['Lion-Veteran'] = 5;
set['items.pets.Lion-Veteran'] = 5;
} else if (user.items.pets['Wolf-Veteran']) {
user.items.pets['Tiger-Veteran'] = 5;
set['items.pets.Tiger-Veteran'] = 5;
} else {
user.items.pets['Wolf-Veteran'] = 5;
set['items.pets.Wolf-Veteran'] = 5;
}
if (count % progressCount === 0) console.warn(`${count} ${user._id}`);
return await user.save();
return await User.update({_id: user._id}, {$set: set}).exec();
}
module.exports = async function processUsers () {
@ -46,6 +48,7 @@ module.exports = async function processUsers () {
.limit(250)
.sort({_id: 1})
.select(fields)
.lean()
.exec();
if (users.length === 0) {