Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const DUP_COUNT = 2000
- const BATCH_SIZE = 1000;
- const doc = {
- expires: ISODate("2025-10-01T12:08:20.153Z"),
- session:
- '{"cookie":{"originalMaxAge":157680000000,"expires":"2025-10-01T12:03:19.734Z","secure":true,"httpOnly":true,"path":"/","sameSite":true},"pairingUuid":"abdbe798-b3ad-4fbb-913c-6362484e8acf","terminalExternalId":"DigitalGoods","customerRelationUuid":"e0505e42-959d-4391-9697-51019edc0bc2","checkInDate":"2020-10-02T12:03:17.178Z","userIssuer":"twint-issuer1"}'
- };
- let inserted = 0;
- while (inserted < DUP_COUNT) {
- const n = Math.min(BATCH_SIZE, DUP_COUNT - inserted);
- const batch = [];
- for (let i = 0; i < n; i++) {
- batch.push(Object.assign({}, doc)); // shallow copy
- }
- const res = db.sessions.insertMany(batch, { ordered: false });
- inserted += Object.keys(res.insertedIds).length;
- // lightweight progress (every ~10 batches)
- if ((inserted / BATCH_SIZE) % 10 === 0 || inserted === DUP_COUNT) {
- print(`Inserted ${inserted} / ${DUP_COUNT}`);
- }
- }
- print(`Done. Inserted ${inserted} documents.`);
Advertisement
Add Comment
Please, Sign In to add comment