Skip to content

Instantly share code, notes, and snippets.

@DiegoPinho
Last active August 6, 2018 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoPinho/e58559efc27ac451f21104e9013bca3c to your computer and use it in GitHub Desktop.
Save DiegoPinho/e58559efc27ac451f21104e9013bca3c to your computer and use it in GitHub Desktop.
// instância do MongoClient
const MongoClient = require('mongodb').MongoClient;
// conexão com o banco de dados remoto exemplomlab
const url = 'SUA_URL_AQUI';
MongoClient.connect(url, (err, db) => {
if(!err) {
console.log('Conectado');
}
//criação da collection Artigos
db.collection('Artigos', (err, collection) => {
collection.insert({title: 'Artigo 1'});
collection.insert({title: 'Artigo 2'});
collection.insert({title: 'Artigo 3'});
db.collection('Artigos').count((err, count) => {
if (err) throw err;
console.log('total linhas inseridas: ' + count);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment