Last active
August 29, 2015 13:58
-
-
Save athap/10007031 to your computer and use it in GitHub Desktop.
Connecting To MongoDB From Node.js Beginner's Basic
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
var MongoClient = require('mongodb').MongoClient; | |
var connectionString = 'mongodb://localhost:27017/test'; | |
// connect to test db | |
MongoClient.connect(connectionString, function(err, db) { | |
if(err) throw err; | |
console.log("CONNECTED"); | |
var q = {name: 'Super Man'}; | |
// query superheroes collection and display result | |
db.collection('heroes').findOne(q,function(err, doc) { | |
if(err) throw err; | |
console.dir(doc); | |
db.close(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment