Skip to content

Instantly share code, notes, and snippets.

@mbleigh
Created August 28, 2010 21:59
Show Gist options
  • Save mbleigh/555625 to your computer and use it in GitHub Desktop.
Save mbleigh/555625 to your computer and use it in GitHub Desktop.
// 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