Skip to content

Instantly share code, notes, and snippets.

@ShawonAshraf
Created August 3, 2019 20:26
Show Gist options
  • Select an option

  • Save ShawonAshraf/705a426fb78e2b77d31ec20c0a3f1b14 to your computer and use it in GitHub Desktop.

Select an option

Save ShawonAshraf/705a426fb78e2b77d31ec20c0a3f1b14 to your computer and use it in GitHub Desktop.
Code for mongodb-nodejs-medium article
const data = require('./data.json');
const games = data.games; // that's what we need actually
const addMultipleDocs = async(docs, db) => {
try {
// const db = client.db();
await db.collection('games').insertMany(docs);
console.log('Multiple Docs Added!');
} catch (e) {
console.log(e.toString());
}
};
// add multiple
await addMultipleDocs(games, db);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment