Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Basic MongoDB Connection with NodeJS
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
You can’t perform that action at this time.