I have a working Node.js app setup and running well when using my local development MongoDB with these settings and code:
var MongoDB = require('mongodb').Db;
var Server = require('mongodb').Server;
var dbPort = 27017;
var dbHost = 'localhost';
var dbName = 'my-db';
var db = new MongoDB(dbName, new Server(dbHost, dbPort, {auto_reconnect: true}), {w: 1});
db.open(function(e, d){
if (e) {
console.log(e);
} else{
console.log('connected to database :: ' + dbName);
}
});
But when I try to connect with my MongoHQ URI I am getting a Failed to Connect error.
I am unsure as how to use the URI: mongodb://username:password@linus.mongohq.com:10022/my-db with the above code.
Edit: Here is the next part of my code to show how I am using the db variable in case it helps with the problem:
var accounts = db.collection('accounts');
/* login validation methods */
exports.autoLogin = function(user, pass, callback)
{
accounts.findOne({user:user}, function(e, o) {
if (o){
o.pass == pass ? callback(o) : callback(null);
} else{
callback(null);
}
});
}
exports.manualLogin = function(user, pass, callback)
{
accounts.findOne({user:user}, function(e, o) {
if (o == null){
callback('user-not-found');
} else{
validatePassword(pass, o.pass, function(err, res) {
if (res){
callback(null, o);
} else{
callback('invalid-password');
}
});
}
});
}