Last active
December 7, 2018 05:23
-
-
Save songthamtung/48438f4ebb6109a321c5a9681a94656c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// searches MongoDb for all users with a rank limit 10000 | |
User.aggregate([ | |
{ | |
$project: { | |
_id: "$_id", | |
rank: "$rank" | |
} | |
}, | |
{ | |
$match: { | |
rank: { $ne: null } | |
} | |
}, | |
{ $limit: 10000 } | |
]).then(items => { | |
items.forEach(function(i) { | |
// Loops through each user to unset the rank | |
User.findOneAndUpdate( | |
{ _id: i._id }, | |
{ $unset: { rank: 1 } }, | |
{ new: true } | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment