Last active
December 27, 2018 00:08
-
-
Save gustavoapolinario/402fe3097e5feddf8f72274a5a7cad57 to your computer and use it in GitHub Desktop.
Simple tester to your node.js connect with mongodb client
This file contains hidden or 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
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