MongoEngine / flask-mongoengine

MongoEngine flask extension with WTF model forms support
Other
841 stars 254 forks source link

Connection refused problem #449

Closed lucasvazq closed 2 years ago

lucasvazq commented 2 years ago

Hello everyone :wave:, I need some help setting up my app.

I'm having trouble connecting to Mongo through the MONGO_URI config and I don't know why. The problem doesn't occur with flask_pymongo, but it does occur with this package.

This is what I'm doing:

app.config["MONGO_URI"] = "mongodb://my_user:my_pass@mongo:27017/my_mongo_db?authSource=admin"
from flask_mongoengine import MongoEngine
db = MongoEngine(app)
class MyCustomCollection(db.Document):
    hello = db.StringField()
MyCustomCollection.objects.create(hello="world")

# Exception: localhost:27017: [Errno 111] Connection refused, Timeout: 30s, Topology Description: ]>

Here I leave a fully reproducible example with a minimal and easy setup:

lucasvazq commented 2 years ago

The solution has arrived! :rocket:

I was able to solve the problem by replacing MONGO_URI with the following config:

app.config["MONGODB_SETTINGS"] = {"host": "mongodb://my_user:my_pass@mongo:27017/my_mongo_db?authSource=admin", "connect": False}