Skip to content

Instantly share code, notes, and snippets.

@pptyasar
Created October 29, 2022 17:31
Show Gist options
  • Save pptyasar/d241fee1c9baeca583ca46547bb1f802 to your computer and use it in GitHub Desktop.
Save pptyasar/d241fee1c9baeca583ca46547bb1f802 to your computer and use it in GitHub Desktop.
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
// ----------Insert Records------------
dbo.collection("customers").deleteMany({});
for (let i = 0; i <1000; i++) {
var myobj = { _id:"VINNUMBERMONDB"+i,name: "Company Inc2 - "+i, address: "Highway 37"+i };
dbo.collection("customers").insertOne(myobj, function(err, res) {
if (err) throw err;
console.log(i+" document inserted");
});
}
//-----OpLogs--------
// db.oplog.rs.find({ns: {$ne: ''}}).sort({ts: -1})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment