Skip to content

Instantly share code, notes, and snippets.

@webjay
Created October 23, 2011 19:41
Show Gist options
  • Save webjay/1307791 to your computer and use it in GitHub Desktop.
Save webjay/1307791 to your computer and use it in GitHub Desktop.
How to connect to MongoDB from Node.js
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.
});
}
});
@bala93kumar
Copy link

can you give sample code to connect with connection string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment