How to connect with username/password to mongodb using native node.js driver

joyent, node-mongodb-native, node.js

Solution

Easier if you just use MongoClient

MongoClient.connect('mongodb://admin:password@localhost:27017/db', function (err, db) {

Problem

I'm using native mongo driver in Joyent cloud, the node.js application runs fine locally but in Joyent when I run with the username/password that they provided it fails to connect. This is the code I use to connect: ``` var db = new MongoDB(dbName, new Server('localhost', 27017 , {auto_reconnect: true}), {w: 1}); db.open(function(e, db){ if (e) { console.log(e); } else{ console.log('connected to database :: ' + dbName); //db.admin().authenticate('admin', '+(uihghjk', function(de , db){ // if(e){ // console.log("could not authenticate"); // }else { //console.log('connected to database :: ' + dbName); // } // }); } }); ``` What's stopping me from connecting successfully?

Original source