Created
April 15, 2025 11:24
-
-
Save polsala/4fba1fb7be823354f60d52ea2de8cdd1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const batchSize = 100000; | |
| let totalDeleted = 0; | |
| const cutoff = new Date("2024-01-01T00:00:00Z"); | |
| const col_name = "giscemisc_action"; | |
| while (true) { | |
| const docs = db[col_name].find( | |
| { create_date: { $lt: cutoff } }, | |
| { _id: 1 } | |
| ).limit(batchSize).toArray(); | |
| if (docs.length === 0) { | |
| print("Deletion completed."); | |
| break; | |
| } | |
| const ids = docs.map(doc => doc._id); | |
| const res = db[col_name].deleteMany({ _id: { $in: ids } }); | |
| totalDeleted += res.deletedCount; | |
| print("Deleted in this batch: " + res.deletedCount + " | Total deleted: " + totalDeleted); | |
| sleep(100); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment