Skip to content

Instantly share code, notes, and snippets.

@webjay
Created October 23, 2011 19:41
Show Gist options
  • Select an option

  • Save webjay/1307791 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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