Skip to content

Instantly share code, notes, and snippets.

@songthamtung
Last active December 7, 2018 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save songthamtung/48438f4ebb6109a321c5a9681a94656c to your computer and use it in GitHub Desktop.
Save songthamtung/48438f4ebb6109a321c5a9681a94656c to your computer and use it in GitHub Desktop.
// 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