Skip to content

Instantly share code, notes, and snippets.

View donsn's full-sized avatar
🚀

Nwachukwu Daniel (DONSN) donsn

🚀
View GitHub Profile
@donsn
donsn / fix-mongo-db-accidental-delete.js
Created April 6, 2023 15:19
Copy data from one MongoDB collection to another collection
// This copies data from the mongodb collection <collection1> to <collection2> preserving the _id field, it will skip if the _id already exists
console.log('Starting mongodb fixes');
var url = "mongodb+srv://<username>:<password>@<clustername>.mongodb.net/<dbname>?retryWrites=true&w=majority";
const { MongoClient } = require('mongodb');
var fs = require('fs');
const databaseName = '<database_name>';
const collectionOne = 'collection1';
const collectionTwo = 'collection2';
let continueProcessing = true;