Created
August 28, 2010 21:59
-
-
Save mbleigh/555625 to your computer and use it in GitHub Desktop.
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
// Change the _open function in mongoose's connection.js to this | |
// and you'll be able to connect to MongoHQ URLS! | |
_open: function(options){ | |
var self = this; | |
this.db = new mongo.Db(this.name, new mongo.Server(this.uri.hostname, this.uri.port, options)); | |
if (this.uri.auth) { | |
var auth = this.uri.auth.split(':'); | |
this.db.open(function(err) { | |
if (err) return self._error("Can't connect to " + url.format(uri)); | |
self.db.authenticate(auth[0],auth[1], function(err) { | |
if (err) return self._error("Can't authenticate to " + url.format(uri)); | |
if (self._close) return self.db.close(); | |
self._connected = true; | |
for (var i in self._collections) self._collections[i].setDb(self.db); | |
self.emit('open'); | |
}); | |
}); | |
} else { | |
this.db.open(function(err){ | |
if (err) return self._error("Can't connect to " + url.format(uri)); | |
if (self._close) return self.db.close(); | |
self._connected = true; | |
for (var i in self._collections) self._collections[i].setDb(self.db); | |
self.emit('open'); | |
}); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment