Skip to content

Instantly share code, notes, and snippets.

@gustavoapolinario
Last active December 27, 2018 00:08
Show Gist options
  • Save gustavoapolinario/402fe3097e5feddf8f72274a5a7cad57 to your computer and use it in GitHub Desktop.
Save gustavoapolinario/402fe3097e5feddf8f72274a5a7cad57 to your computer and use it in GitHub Desktop.
Simple tester to your node.js connect with mongodb client
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://admin:adminadmin@$SERVER_IP:27017/exampleDb";
MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
var myobj = { name: "Company Inc", address: "Highway 37" };
dbo.collection("customers").insertOne(myobj, function(err, res) {
if (err) throw err;
console.log("1 document inserted");
db.close();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment