Created
August 3, 2019 20:24
-
-
Save ShawonAshraf/3eea9a3d1bc8a5d9b611c3287e572323 to your computer and use it in GitHub Desktop.
Code for mongodb-nodejs-medium article
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
| // add a single element | |
| const singleDoc = { | |
| name: 'Red Dead Redemption 2', | |
| platform: 'PS4', | |
| publisher: 'Rockstar' | |
| }; | |
| const addOneDocument = async(doc, db) => { | |
| try { | |
| // const db = client.db(); | |
| await db.collection('games').insertOne(doc); | |
| console.log('Document has been updated! ...'); | |
| } catch (e) { | |
| console.log(e.toString()); | |
| } | |
| }; | |
| await addOneDocument(singleDoc, db); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment