Created
October 23, 2011 19:41
-
-
Save webjay/1307791 to your computer and use it in GitHub Desktop.
How to connect to MongoDB from Node.js
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 mongodb = require('mongodb'); | |
var server = new mongodb.Server('hostname', portnumber, {auto_reconnect: true}); | |
var db = new mongodb.Db('databasename', server); | |
db.open(function (err, db) { | |
if (err) { | |
console.error(err); | |
} else { | |
db.authenticate('username', 'password', function(){ | |
// ready for you, sir. | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you give sample code to connect with connection string