Closed crabmusket closed 11 years ago
Looks great! It seems that MongoHQ is a little ad-hoc. Do they work with a mongodb: prefix also?
Whoops, I meant a mongodb:
prefix. MongoLab uses that URI as well, and the environment variable is called "MONGOLAB_URI"
. OpenRedis uses "OPENREDIS_URL"
and redis:
, so it seems like this is a common point of difference. This was the lowest-impact way I could see to do it, while keeping most of the existing code.
I should mention that test.hs
still runs fine - there's no API change.
should there be a Web.Heroku.MongoDB with 'mongodb:' bound and a function for mongoHQ and mongoLab?
I have one waiting to pull request ;). I actually have Web.Heroku.MongoHQ
that exports dbConnParams
and parseDatabaseUrl
with the MongoHQ settings. The idea would be to have another module again for MongoLab. Unless you'd prefer to have a single module per actual database.
Generally I prefer combining modules in a situation where there are few exports. It makes for a faster install time and a smaller hierarchy with just one file to open in an editor. I generally break out modules to manage import/export, keep module size small enough to comprehend, or create strong logical divisions. Not a big deal though
Hmm, I'm finding other changes I need to make to get this working properly with Mongo. I've fixed the issues I can find relating to this script, but when I push my code to Heroku I get a user error (connection timed out)
. I read that Yesod didn't support authenticating mongo connections ca. 2012. Is that still the case?
No, there is support in Persistent for auth connection parameters and they can be specified in the mongoDB.yaml file. But this is a url parser, so there may be some work to make it work with what persistent is expecting, maybe you can come up with the delta. I do see "database" instead of "dbname". Arguably persistent-mongoDB itself should be able to parse a connection url.
I found the problem. I was incorrectly parsing the port number, which I didn't leave to the default value. This is what I ended up with - and after we get MongoDB support in this module on Hackage then I'll be able to use it ;P.
I've refactored the library to allow it to search for different environment variables and database URI schemes. For example, I'm using a MongoHQ database where the environment variable is called
"MONGOHQ_URL"
and the database URL starts withmongo:
.