Skip to content

Instantly share code, notes, and snippets.

@athap
Last active August 29, 2015 13:58
Show Gist options
  • Save athap/10007031 to your computer and use it in GitHub Desktop.
Save athap/10007031 to your computer and use it in GitHub Desktop.
Connecting To MongoDB From Node.js Beginner's Basic
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