Closed btaitelb closed 10 years ago
First, thanks a lot for contributing. Hope MotorEngine is helping you.
This pull request is not required, though. Maybe a pull request to update docs on connecting would be better, ehehehehe.
Just pass host=env["MONGOLAB_URI"]. Hosts work with either an actual hostname or a connection string.
The issue I have is that you can't just call connect(host=mongolab_uri)
, you have to call connect(db, host=mongolab_uri)
, which involves passing the uri through a regex to find the db name, since it's of the format mongodb://host:port/name
or mongodb://user:password@host:port/name
I'll have to try it later, but I'm pretty sure the db name is used only for future reference (if you have many connections to the DB). The name that's actually used for connection is the database in the string.
What I mean is that if you have:
connect("my-pretty-app", "mongodb://user:password@host:port/name")
"my-pretty-app" is only useful if you want to retrieve this specific database connection. The database motorengine will connect to is "name". If that's not the case, then we should fix it.
I'm not able to get the functionality you're describing in practice in my app (I'm getting pymongo.errors.OperationFailure: database error: not authorized for query on my_db_name.User
). I'm having trouble coming up with a test case that reproduces this however, and it feels more like an integration test might be needed (e.g. connect one way and writes some data, then connect the other way and read it back to ensure that the same db and collection are used each time). Any suggestions for how I can write the test? Do you think it should be possible as a unit test? Thanks!
I wanted a way to be able to pass a connection uri (e.g.
MONGOLAB_URI
in the environment) to the connect function. Without this, I had to parse the uri just to get the db name, and then pass the uri itself as thehost
keyword argument.