Skip to content

Commit

Permalink
Remove field AccountsDeclaredAsLevyPayers from Users collection
Browse files Browse the repository at this point in the history
  • Loading branch information
VasanthaKasirajan3008 committed Jan 22, 2020
1 parent 72b7244 commit 0be2daa
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
print("Start removing accountsDeclaredAsLevyPayers from users.");

const query = {
"accountsDeclaredAsLevyPayers": { $exists: true }
},
batchUpdateLimit = 500,
coll = db.users;
let passThrough = 1,
maxLoops = Math.ceil(coll.find().count(query) / batchUpdateLimit);

if (maxLoops === 0) {
maxLoops = 1;
}

print(query);

do {
let matchedDocs = coll.aggregate([
{
$match: query
},
{
$sort: { "lastUpdated": 1 }
},
{
$limit: batchUpdateLimit
}
]);

print(`Found ${matchedDocs._batch.length} document(s) to operate on in pass-through ${passThrough} of ${maxLoops}.`);

while (matchedDocs.hasNext()) {
let doc = matchedDocs.next();

let writeResult = coll.update({
"_id": doc._id
}, {
$unset: { "accountsDeclaredAsLevyPayers": "" }
});

if (writeResult.hasWriteConcernError()) {
printjson(writeResult.writeConcernError);
quit(14);
}

print(`Updated document '${doc._id}', removed accountsDeclaredAsLevyPayers.`);
}

passThrough++;
}
while (passThrough <= maxLoops && coll.find().count(query) > 0);

print("Finished removing accountsDeclaredAsLevyPayers from users.");
}

0 comments on commit 0be2daa

Please sign in to comment.