Laleet
Laleet

Reputation: 51

Connect to MongoDB atlas cluster with flask-mongoengine

I am trying to connect with mongodb atlas from my flask app using flask-mongoengine.

DB_URI =  "mongodb+srv://flask_app_user:[email protected]/flask_app?retryWrites=true&w=majority"

def create_app():
    app = Flask(__name__)
    app.secret_key = os.environ.get('SECRET_KEY', 'replace_me_32437264278642')
    app.config['MONGODB_SETTINGS'] = {
        'host': os.environ.get('MONGODB_URI', DB_URI)
    }
    MongoEngine(app)
    socketio.init_app(app)
    SSLify(app)

    return app

But I am getting an error,

pymongo.errors.InvalidURI: Invalid URI scheme: URI must begin with 'mongodb://'

How can I use mongo atlas with flask_mongoengine? I don't want to stick with flask_mongoengine. I don't want to change that.

Upvotes: 1

Views: 427

Answers (1)

Ruben
Ruben

Reputation: 152

It worked correctly for me with the latest version flask_mongoengine-1.0.0 and pymongo-3.11.2

It seems you're using the host from MONGODB_URI env var... What do you have in MONGODB_URI?? Could you share also which version are you using?

Upvotes: 1

Related Questions