Last active
May 19, 2019 11:21
-
-
Save kerminz/17d386cd0a4c1881872a36686cb4e6f5 to your computer and use it in GitHub Desktop.
Basic MongoDB Connection with NodeJS
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
const mongodb = require('mongodb') | |
const MongoClient = mongodb.MongoClient | |
const connectionURL = 'mongodb://127.0.0.1:27017' | |
const databaseName = 'customDatabaseName' | |
MongoClient.connect(connectionURL, { useNewUrlParser: true }, (error, client) => { | |
if (error) { | |
return console.log('Unable to connect to database!') | |
} | |
const db = client.db(databaseName) | |
db.collection('users').insertOne({ | |
name: 'Kermin', | |
age: 32 | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment