Skip to content

Instantly share code, notes, and snippets.

@danielnunesdc
Created January 5, 2019 01:49
Show Gist options
  • Save danielnunesdc/8bcb9985f01d2b8da49ff0e385ba484b to your computer and use it in GitHub Desktop.
Save danielnunesdc/8bcb9985f01d2b8da49ff0e385ba484b to your computer and use it in GitHub Desktop.
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