Last active
January 22, 2018 22:44
-
-
Save mathiasgheno/9e6b58275758a583703aaba417ee1d4b to your computer and use it in GitHub Desktop.
MongoDB Auth Node.js Snippet
This file contains 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 usuario = 'myUserAdmin'; | |
const senha = 'abc123@'; | |
const url = `mongodb://localhost:27017/admin`; | |
mongodb | |
.MongoClient | |
.connect(url) | |
.then((db) => { | |
db.authenticate(usuario, senha) | |
.then(() => { | |
db.db('teste') | |
.collection('admin') | |
.insertOne({funcionando: true}) | |
.then((resultadoOperacao) => { | |
console.log(resultadoOperacao.insertedId); | |
}); | |
}); | |
}) | |
.catch(reason => console.log('Erro ao conectar: ', reason)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment