mongodb-labs / flask-pymongo

PyMongo support for Flask applications

Repository from Github https://github.commongodb-labs/flask-pymongoRepository from Github https://github.commongodb-labs/flask-pymongo

MONGO_URI forcefully expects database name

bhairav13 opened this issue · comments

Hello,

I configure MONGO_URI as shown below:

    app.config.update(
        # Documentation says URI is preferred
        MONGO_URI="mongodb://{}:{}/".format(dbhost, int(dbport) or 27017),
        # Use OrderedDict for the documents
        MONGO_DOCUMENT_CLASS=OrderedDict,
    )
    connection = PyMongo(app)

I don't include the database name because I prefer to make a connection and get a list of the databases first. Then I "attach" to the databases one-by-one to extract some information from them.

However, I now get a ValueError exception that: "Your URI must specify a database name".

Is there any way to not force having to supply the database name? This used to work in versions < 2, so hoping we can get a similar behavior in the newer versions.

That seems reasonable. I've cut a new branch (https://github.com/dcrosta/flask-pymongo/tree/allow-no-db-name), and if everything looks good on the build, I'll try to cut the release later today.

Wow! Many thanks for the quick turn-around!

Thank you @dcrosta. I'll pick it up and test it out immediately. Just an FYI, on the below page, the 2.2.0 version is referring to Issue #114 instead of this issue (#117).

🤦‍♂️

How can l use this feature.1 can't find example fo this.